@@ -31,15 +31,15 @@ static class SubD extends SuperType {
3131 public int d ;
3232 }
3333
34- // "Empty" bean, to test [JACKSON-366]
34+ // "Empty" bean
3535 @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME )
3636 static abstract class BaseBean { }
3737
3838 static class EmptyBean extends BaseBean { }
3939
4040 static class EmptyNonFinal { }
4141
42- // Verify combinations with [JACKSON-510]
42+ // Verify combinations
4343
4444 static class PropertyBean
4545 {
@@ -50,7 +50,6 @@ static class PropertyBean
5050 public PropertyBean (SuperType v ) { value = v ; }
5151 }
5252
53- // And then [JACKSON-614]
5453 @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME , include =As .PROPERTY ,
5554 property ="#type" ,
5655 defaultImpl =DefaultImpl .class )
@@ -102,25 +101,39 @@ public Issue1125Wrapper() { }
102101 public Issue1125Wrapper (Base1125 v ) { value = v ; }
103102 }
104103
105- @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME )
104+ @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME , defaultImpl = Default1125 . class )
106105 @ JsonSubTypes ({ @ JsonSubTypes .Type (Interm1125 .class ) })
107106 static class Base1125 {
108107 public int a ;
109108 }
110109
111110 @ JsonSubTypes ({ @ JsonSubTypes .Type (value =Impl1125 .class , name ="impl" ) })
112- static class Interm1125 extends Base1125 { }
111+ static class Interm1125 extends Base1125 {
112+ public int b ;
113+ }
113114
114115 static class Impl1125 extends Interm1125 {
115- public int b ;
116+ public int c ;
116117
117118 public Impl1125 () { }
118- public Impl1125 (int a0 , int b0 ) {
119+ public Impl1125 (int a0 , int b0 , int c0 ) {
119120 a = a0 ;
120121 b = b0 ;
122+ c = c0 ;
121123 }
122124 }
123125
126+ static class Default1125 extends Interm1125 {
127+ public int def ;
128+
129+ Default1125 () { }
130+ public Default1125 (int a0 , int b0 , int def0 ) {
131+ a = a0 ;
132+ b = b0 ;
133+ def = def0 ;
134+ }
135+ }
136+
124137 /*
125138 /**********************************************************
126139 /* Unit tests
@@ -287,15 +300,29 @@ public void testViaAtomic() throws Exception {
287300 }
288301
289302 // [databind#1125]: properties from base class too
290- public void testIssue1125 () throws Exception
303+
304+ public void testIssue1125NonDefault () throws Exception
291305 {
292- String json = MAPPER .writeValueAsString (new Issue1125Wrapper (new Impl1125 (1 , 2 )));
306+ String json = MAPPER .writeValueAsString (new Issue1125Wrapper (new Impl1125 (1 , 2 , 3 )));
293307
294308 Issue1125Wrapper result = MAPPER .readValue (json , Issue1125Wrapper .class );
295309 assertNotNull (result .value );
296310 assertEquals (Impl1125 .class , result .value .getClass ());
297311 Impl1125 impl = (Impl1125 ) result .value ;
298312 assertEquals (1 , impl .a );
299313 assertEquals (2 , impl .b );
314+ assertEquals (3 , impl .c );
315+ }
316+
317+ public void testIssue1125WithDefault () throws Exception
318+ {
319+ Issue1125Wrapper result = MAPPER .readValue (aposToQuotes ("{'value':{'a':3,'def':9,'b':5}}" ),
320+ Issue1125Wrapper .class );
321+ assertNotNull (result .value );
322+ assertEquals (Default1125 .class , result .value .getClass ());
323+ Default1125 impl = (Default1125 ) result .value ;
324+ assertEquals (3 , impl .a );
325+ assertEquals (5 , impl .b );
326+ assertEquals (9 , impl .def );
300327 }
301328}
0 commit comments