-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af2414a
commit 0543bf1
Showing
10 changed files
with
643 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
hibernate3/src/test/java/com/fasterxml/jackson/datatype/hibernate3/Polymorphic81Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.fasterxml.jackson.datatype.hibernate3; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class Polymorphic81Test extends BaseTest | ||
{ | ||
static class TestLayout { | ||
public RecordFilters recordFilters = new RecordFilters(); | ||
|
||
public TestLayout addRecordFilter(AbstractRecordFilter recordFilter) { | ||
recordFilters.filters.add(recordFilter); | ||
return this; | ||
} | ||
} | ||
|
||
static class RecordFilters implements RecordFilter { | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = EmptyRecordFilter.class) | ||
// ,@JsonSubTypes.Type(value = RangeRecordFilter.class) } | ||
}) | ||
public List<AbstractRecordFilter> filters = new ArrayList<AbstractRecordFilter>(); | ||
} | ||
|
||
public interface RecordFilter { } | ||
|
||
static abstract class AbstractRecordFilter implements RecordFilter { } | ||
|
||
@JsonTypeName(value="emptyRecordFilter") | ||
static class EmptyRecordFilter extends AbstractRecordFilter { | ||
Expression expr; | ||
|
||
EmptyRecordFilter() { | ||
} | ||
|
||
public EmptyRecordFilter(Expression expr) { | ||
this.expr = expr; | ||
} | ||
} | ||
|
||
static class Expression { | ||
private String expression; | ||
|
||
Expression() { } | ||
|
||
public Expression(String expression) { | ||
this.expression = expression; | ||
} | ||
|
||
public String getExpression() { | ||
return expression; | ||
} | ||
|
||
public static Expression simpleFieldExpression(String field) { | ||
return new Expression("${" + field + "}"); | ||
} | ||
} | ||
|
||
public void testPolymorphic81() throws Exception | ||
{ | ||
final ObjectMapper mapper = mapperWithModule(true); | ||
|
||
final TestLayout layout = new TestLayout() | ||
.addRecordFilter(new EmptyRecordFilter(Expression.simpleFieldExpression("id"))); | ||
|
||
// uncomment the line below to see the problem | ||
// mapper.registerModule(new Hibernate4Module()); | ||
|
||
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(layout); | ||
// System.out.println("OUTPUT:\n"+json); | ||
|
||
final TestLayout restoredLayout = | ||
mapper.readerFor(TestLayout.class).readValue(json); | ||
assertNotNull(restoredLayout); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.