1
1
package com .fasterxml .jackson .perf .json ;
2
2
3
- import com .fasterxml .jackson .annotation .JsonCreator ;
4
3
import com .fasterxml .jackson .annotation .JsonProperty ;
5
4
import com .fasterxml .jackson .core .JsonFactory ;
5
+ import com .fasterxml .jackson .core .JsonFactoryBuilder ;
6
6
import com .fasterxml .jackson .core .JsonParser ;
7
+ import com .fasterxml .jackson .core .TSFBuilder ;
7
8
import com .fasterxml .jackson .core .type .TypeReference ;
8
9
import com .fasterxml .jackson .databind .DeserializationFeature ;
9
10
import com .fasterxml .jackson .databind .ObjectMapper ;
10
11
import com .fasterxml .jackson .databind .ObjectReader ;
12
+ import com .fasterxml .jackson .databind .json .JsonMapper ;
11
13
import org .openjdk .jmh .annotations .Benchmark ;
12
14
import org .openjdk .jmh .annotations .BenchmarkMode ;
13
15
import org .openjdk .jmh .annotations .Mode ;
@@ -34,24 +36,24 @@ public class JsonArbitraryFieldNameBenchmark {
34
36
public enum FactoryMode {
35
37
DEFAULT () {
36
38
@ Override
37
- JsonFactory apply (JsonFactory factory ) {
39
+ < F extends JsonFactory , B extends TSFBuilder < F , B >> B apply (B factory ) {
38
40
return factory ;
39
41
}
40
42
},
41
43
NO_INTERN () {
42
44
@ Override
43
- JsonFactory apply (JsonFactory factory ) {
45
+ < F extends JsonFactory , B extends TSFBuilder < F , B >> B apply (B factory ) {
44
46
return factory .disable (JsonFactory .Feature .INTERN_FIELD_NAMES );
45
47
}
46
48
},
47
49
NO_CANONICALIZE () {
48
50
@ Override
49
- JsonFactory apply (JsonFactory factory ) {
51
+ < F extends JsonFactory , B extends TSFBuilder < F , B >> B apply (B factory ) {
50
52
return factory .disable (JsonFactory .Feature .CANONICALIZE_FIELD_NAMES );
51
53
}
52
54
};
53
55
54
- abstract JsonFactory apply (JsonFactory factory );
56
+ abstract < F extends JsonFactory , B extends TSFBuilder < F , B >> B apply (B factory );
55
57
}
56
58
57
59
/**
@@ -109,10 +111,11 @@ public enum InputShape {
109
111
110
112
@ Setup
111
113
public void setup () {
112
- factory = mode .apply (new JsonFactory () );
113
- ObjectMapper mapper = new ObjectMapper (factory )
114
+ factory = mode .apply (new JsonFactoryBuilder ()). build ( );
115
+ ObjectMapper mapper = JsonMapper . builder (factory )
114
116
// Use FAIL_ON_UNKNOWN_PROPERTIES to ensure the benchmark inputs are valid
115
- .enable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES );
117
+ .enable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
118
+ .build ();
116
119
reader = mapper .readerFor (shape .typereference );
117
120
}
118
121
@@ -128,24 +131,13 @@ public Object parse() throws IOException {
128
131
* fields to cover a mix of reused and arbitrary json keys.
129
132
*/
130
133
public static final class SimpleClass {
134
+ @ JsonProperty ("fieldWithMap" )
131
135
public Map <String , Boolean > fieldWithMap ;
132
-
136
+ @ JsonProperty ( "stringOne" )
133
137
public String stringOne ;
134
-
138
+ @ JsonProperty ( "stringTwo" )
135
139
public String stringTwo ;
136
-
140
+ @ JsonProperty ( "stringThree" )
137
141
public String stringThree ;
138
-
139
- @ JsonCreator (mode = JsonCreator .Mode .PROPERTIES )
140
- SimpleClass (
141
- @ JsonProperty ("fieldWithMap" ) Map <String , Boolean > fieldWithMap ,
142
- @ JsonProperty ("stringOne" ) String stringOne ,
143
- @ JsonProperty ("stringTwo" ) String stringTwo ,
144
- @ JsonProperty ("stringThree" ) String stringThree ) {
145
- this .fieldWithMap = fieldWithMap ;
146
- this .stringOne = stringOne ;
147
- this .stringTwo = stringTwo ;
148
- this .stringThree = stringThree ;
149
- }
150
142
}
151
143
}
0 commit comments