@@ -31,15 +31,15 @@ static class SubD extends SuperType {
31
31
public int d ;
32
32
}
33
33
34
- // "Empty" bean, to test [JACKSON-366]
34
+ // "Empty" bean
35
35
@ JsonTypeInfo (use =JsonTypeInfo .Id .NAME )
36
36
static abstract class BaseBean { }
37
37
38
38
static class EmptyBean extends BaseBean { }
39
39
40
40
static class EmptyNonFinal { }
41
41
42
- // Verify combinations with [JACKSON-510]
42
+ // Verify combinations
43
43
44
44
static class PropertyBean
45
45
{
@@ -50,7 +50,6 @@ static class PropertyBean
50
50
public PropertyBean (SuperType v ) { value = v ; }
51
51
}
52
52
53
- // And then [JACKSON-614]
54
53
@ JsonTypeInfo (use =JsonTypeInfo .Id .NAME , include =As .PROPERTY ,
55
54
property ="#type" ,
56
55
defaultImpl =DefaultImpl .class )
@@ -102,25 +101,39 @@ public Issue1125Wrapper() { }
102
101
public Issue1125Wrapper (Base1125 v ) { value = v ; }
103
102
}
104
103
105
- @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME )
104
+ @ JsonTypeInfo (use =JsonTypeInfo .Id .NAME , defaultImpl = Default1125 . class )
106
105
@ JsonSubTypes ({ @ JsonSubTypes .Type (Interm1125 .class ) })
107
106
static class Base1125 {
108
107
public int a ;
109
108
}
110
109
111
110
@ 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
+ }
113
114
114
115
static class Impl1125 extends Interm1125 {
115
- public int b ;
116
+ public int c ;
116
117
117
118
public Impl1125 () { }
118
- public Impl1125 (int a0 , int b0 ) {
119
+ public Impl1125 (int a0 , int b0 , int c0 ) {
119
120
a = a0 ;
120
121
b = b0 ;
122
+ c = c0 ;
121
123
}
122
124
}
123
125
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
+
124
137
/*
125
138
/**********************************************************
126
139
/* Unit tests
@@ -287,15 +300,29 @@ public void testViaAtomic() throws Exception {
287
300
}
288
301
289
302
// [databind#1125]: properties from base class too
290
- public void testIssue1125 () throws Exception
303
+
304
+ public void testIssue1125NonDefault () throws Exception
291
305
{
292
- String json = MAPPER .writeValueAsString (new Issue1125Wrapper (new Impl1125 (1 , 2 )));
306
+ String json = MAPPER .writeValueAsString (new Issue1125Wrapper (new Impl1125 (1 , 2 , 3 )));
293
307
294
308
Issue1125Wrapper result = MAPPER .readValue (json , Issue1125Wrapper .class );
295
309
assertNotNull (result .value );
296
310
assertEquals (Impl1125 .class , result .value .getClass ());
297
311
Impl1125 impl = (Impl1125 ) result .value ;
298
312
assertEquals (1 , impl .a );
299
313
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 );
300
327
}
301
328
}
0 commit comments