8
8
import com .fasterxml .jackson .databind .BaseMapTest ;
9
9
import com .fasterxml .jackson .databind .JsonNode ;
10
10
import com .fasterxml .jackson .databind .ObjectMapper ;
11
- import com .fasterxml .jackson .databind .module .SimpleModule ;
12
11
13
12
public class RaceCondition738Test extends BaseMapTest
14
13
{
15
- @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , include = JsonTypeInfo .As .WRAPPER_OBJECT )
16
- @ JsonSubTypes ({
17
- @ JsonSubTypes .Type (value = TypeOne .class , name = "one" ),
18
- @ JsonSubTypes .Type (value = TypeTwo .class , name = "two" ),
19
- @ JsonSubTypes .Type (value = TypeThree .class , name = "three" )
20
- })
21
14
static abstract class AbstractHasSubTypes implements HasSubTypes { }
22
15
23
16
static class TypeOne extends AbstractHasSubTypes {
@@ -35,36 +28,10 @@ public String getType() {
35
28
}
36
29
}
37
30
38
- static class TypeTwo extends AbstractHasSubTypes {
39
- private final String id ;
40
- public TypeTwo (String id ) {
41
- this .id = id ;
42
- }
43
- @ JsonProperty
44
- public String getId () {
45
- return id ;
46
- }
47
- @ Override
48
- public String getType () {
49
- return TypeTwo .class .getSimpleName ();
50
- }
51
- }
52
-
53
- static class TypeThree extends AbstractHasSubTypes {
54
- private final String id ;
55
- public TypeThree (String id ) {
56
- this .id = id ;
57
- }
58
- @ JsonProperty
59
- public String getId () {
60
- return id ;
61
- }
62
- @ Override
63
- public String getType () {
64
- return TypeThree .class .getSimpleName ();
65
- }
66
- }
67
-
31
+ @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , include = JsonTypeInfo .As .WRAPPER_OBJECT )
32
+ @ JsonSubTypes ({
33
+ @ JsonSubTypes .Type (value = TypeOne .class , name = "one" )
34
+ })
68
35
public interface HasSubTypes {
69
36
String getType ();
70
37
}
@@ -89,12 +56,13 @@ public HasSubTypes getHasSubTypes() {
89
56
*/
90
57
91
58
public void testRepeatedly () throws Exception {
92
- for (int i = 0 ; i < 1000 ; i ++) {
93
- runOnce ();
59
+ final int COUNT = 50 ;
60
+ for (int i = 0 ; i < COUNT ; i ++) {
61
+ runOnce (i , COUNT );
94
62
}
95
63
}
96
64
97
- void runOnce () throws Exception {
65
+ void runOnce (int round , int max ) throws Exception {
98
66
final ObjectMapper mapper = getObjectMapper ();
99
67
Callable <String > writeJson = new Callable <String >() {
100
68
@ Override
@@ -120,17 +88,14 @@ public String call() throws Exception {
120
88
JsonNode wrapped = tree .get ("hasSubTypes" );
121
89
122
90
if (!wrapped .has ("one" )) {
123
- throw new IllegalStateException ("Missing 'one', source: " +json );
91
+ System .out .println ("JSON wrong: " +json );
92
+ throw new IllegalStateException ("Round #" +round +"/" +max +" ; missing property 'one', source: " +json );
124
93
}
94
+ System .out .println ("JSON fine: " +json );
125
95
}
126
96
}
127
97
128
98
private static ObjectMapper getObjectMapper () {
129
- SimpleModule module = new SimpleModule ("subTypeRace" );
130
- module .setMixInAnnotation (HasSubTypes .class , AbstractHasSubTypes .class );
131
-
132
- ObjectMapper mapper = new ObjectMapper ();
133
- mapper .registerModule (module );
134
- return mapper ;
99
+ return new ObjectMapper ();
135
100
}
136
101
}
0 commit comments