Skip to content

Commit e1b2009

Browse files
committed
Bit more testing for default-typing, as.property inclusion
1 parent 152aabb commit e1b2009

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/test/java/com/fasterxml/jackson/databind/jsontype/TestDefaultForObject.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ enum Choice { YES, NO; }
3232
* Another enum type, but this time forcing sub-classing
3333
*/
3434
enum ComplexChoice {
35-
MAYBE(true), PROBABLY_NOT(false);
35+
MAYBE(true), PROBABLY_NOT(false);
3636

37-
private boolean state;
37+
private boolean state;
3838

39-
private ComplexChoice(boolean b) { state = b; }
39+
private ComplexChoice(boolean b) { state = b; }
4040

4141
@Override
42-
public String toString() { return String.valueOf(state); }
42+
public String toString() { return String.valueOf(state); }
4343
}
4444

4545
// [JACKSON-311]
@@ -113,6 +113,24 @@ public void testBeanAsObject() throws Exception
113113
assertEquals("abc", ((StringBean) result[0]).name);
114114
}
115115

116+
// with 2.5, another test to check that "as-property" is valid option
117+
public void testBeanAsObjectUsingAsProperty() throws Exception
118+
{
119+
ObjectMapper m = new ObjectMapper();
120+
m.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL,
121+
".hype");
122+
// note: need to wrap, to get declared as Object
123+
String json = m.writeValueAsString(new StringBean("abc"));
124+
125+
System.err.println("JSON == "+json);
126+
127+
// Ok: serialization seems to work as expected. Now deserialize:
128+
Object result = m.readValue(json, Object.class);
129+
assertNotNull(result);
130+
assertEquals(StringBean.class, result.getClass());
131+
assertEquals("abc", ((StringBean) result).name);
132+
}
133+
116134
/**
117135
* Unit test that verifies that an abstract bean is stored with type information
118136
* if default type information is enabled for non-concrete types.

0 commit comments

Comments
 (0)