1
- package com .fasterxml .jackson .failing ;
1
+ package com .fasterxml .jackson .databind . jsontype ;
2
2
3
3
import com .fasterxml .jackson .annotation .JsonInclude ;
4
4
import com .fasterxml .jackson .databind .BaseMapTest ;
5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
+ import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
6
7
7
- public class Generic1133Test extends BaseMapTest
8
+ public class Generic1128Test extends BaseMapTest
8
9
{
9
10
@ SuppressWarnings ("rawtypes" )
10
11
static abstract class HObj <M extends HObj > {
11
12
public long id ;
13
+
14
+ // important: do not serialize as subtype, but only as type that
15
+ // is statically recognizable here.
16
+ @ JsonSerialize (typing =JsonSerialize .Typing .STATIC )
12
17
public M parent ;
13
18
}
14
19
@@ -44,7 +49,6 @@ static class DevMContainer extends ContainerBase<DevM>{ }
44
49
public void testIssue1128 () throws Exception
45
50
{
46
51
ObjectMapper mapper = new ObjectMapper ();
47
- // mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
48
52
mapper .setSerializationInclusion (JsonInclude .Include .NON_EMPTY );
49
53
50
54
final DevMContainer devMContainer1 = new DevMContainer ();
@@ -55,10 +59,11 @@ public void testIssue1128() throws Exception
55
59
devMContainer1 .entity = entity ;
56
60
57
61
String json = mapper .writeValueAsString (devMContainer1 );
58
- // String json = "{\"entity\":{\"id\":0,\"parent\":{\"id\":2,\"p1\":0},\"p1\":0,\"m1\":0}}";
59
-
60
- System .out .println ("serializedContainer = " + json );
62
+
63
+ // System.out.println("serializedContainer = " + json);
61
64
final DevMContainer devMContainer = mapper .readValue (json , DevMContainer .class );
62
- System .out .println ("devMContainer.getEntity().getParent().getId() = " + devMContainer .entity .parent .id );
65
+ long id = devMContainer .entity .parent .id ;
66
+ // System.out.println("devMContainer.getEntity().getParent().getId() = " + id);
67
+ assertEquals (2 , id );
63
68
}
64
69
}
0 commit comments