31
31
import tools .jackson .databind .DeserializationFeature ;
32
32
import tools .jackson .databind .JavaType ;
33
33
import tools .jackson .databind .JsonNode ;
34
- import tools .jackson .databind .ObjectMapper ;
35
34
import tools .jackson .databind .json .JsonMapper ;
36
35
37
36
import org .springframework .integration .mapping .support .JsonHeaders ;
41
40
* Jackson 3 JSON-processor (@link https://github.com/FasterXML)
42
41
* {@linkplain JsonObjectMapper} implementation.
43
42
* Delegates {@link #toJson} and {@link #fromJson}
44
- * to the {@linkplain ObjectMapper }
43
+ * to the {@linkplain JsonMapper }
45
44
* <p>
46
45
* It customizes Jackson's default properties with the following ones:
47
46
* <ul>
57
56
*/
58
57
public class JacksonJsonObjectMapper extends AbstractJacksonJsonObjectMapper <JsonNode , JsonParser , JavaType > {
59
58
60
- private final ObjectMapper objectMapper ;
59
+ private final JsonMapper jsonMapper ;
61
60
62
61
public JacksonJsonObjectMapper () {
63
- this .objectMapper = JsonMapper .builder ()
62
+ this .jsonMapper = JsonMapper .builder ()
64
63
.findAndAddModules (JacksonJsonObjectMapper .class .getClassLoader ())
65
64
.disable (DeserializationFeature .FAIL_ON_TRAILING_TOKENS )
66
65
.build ();
67
66
}
68
67
69
- public JacksonJsonObjectMapper (ObjectMapper objectMapper ) {
70
- Assert .notNull (objectMapper , "objectMapper must not be null" );
71
- this .objectMapper = objectMapper ;
68
+ public JacksonJsonObjectMapper (JsonMapper jsonMapper ) {
69
+ Assert .notNull (jsonMapper , "jsonMapper must not be null" );
70
+ this .jsonMapper = jsonMapper ;
72
71
}
73
72
74
- public ObjectMapper getObjectMapper () {
75
- return this .objectMapper ;
73
+ public JsonMapper getObjectMapper () {
74
+ return this .jsonMapper ;
76
75
}
77
76
78
77
@ Override
79
78
public String toJson (Object value ) throws IOException {
80
79
try {
81
- return this .objectMapper .writeValueAsString (value );
80
+ return this .jsonMapper .writeValueAsString (value );
82
81
}
83
82
catch (JacksonException e ) {
84
83
throw new IOException (e );
@@ -88,7 +87,7 @@ public String toJson(Object value) throws IOException {
88
87
@ Override
89
88
public void toJson (Object value , Writer writer ) throws IOException {
90
89
try {
91
- this .objectMapper .writeValue (writer , value );
90
+ this .jsonMapper .writeValue (writer , value );
92
91
}
93
92
catch (JacksonException e ) {
94
93
throw new IOException (e );
@@ -99,33 +98,33 @@ public void toJson(Object value, Writer writer) throws IOException {
99
98
public JsonNode toJsonNode (Object json ) throws IOException {
100
99
try {
101
100
if (json instanceof String ) {
102
- return this .objectMapper .readTree ((String ) json );
101
+ return this .jsonMapper .readTree ((String ) json );
103
102
}
104
103
else if (json instanceof byte []) {
105
- return this .objectMapper .readTree ((byte []) json );
104
+ return this .jsonMapper .readTree ((byte []) json );
106
105
}
107
106
else if (json instanceof File ) {
108
- return this .objectMapper .readTree ((File ) json );
107
+ return this .jsonMapper .readTree ((File ) json );
109
108
}
110
109
else if (json instanceof URL ) {
111
- return this .objectMapper .readTree ((URL ) json );
110
+ return this .jsonMapper .readTree ((URL ) json );
112
111
}
113
112
else if (json instanceof InputStream ) {
114
- return this .objectMapper .readTree ((InputStream ) json );
113
+ return this .jsonMapper .readTree ((InputStream ) json );
115
114
}
116
115
else if (json instanceof Reader ) {
117
- return this .objectMapper .readTree ((Reader ) json );
116
+ return this .jsonMapper .readTree ((Reader ) json );
118
117
}
119
118
}
120
119
catch (JacksonException e ) {
121
120
if (!(json instanceof String ) && !(json instanceof byte [])) {
122
121
throw new IOException (e );
123
122
}
124
- // Otherwise the input might not be valid JSON, fallback to TextNode with ObjectMapper .valueToTree()
123
+ // Otherwise the input might not be valid JSON, fallback to TextNode with JsonMapper .valueToTree()
125
124
}
126
125
127
126
try {
128
- return this .objectMapper .valueToTree (json );
127
+ return this .jsonMapper .valueToTree (json );
129
128
}
130
129
catch (JacksonException e ) {
131
130
throw new IOException (e );
@@ -136,22 +135,22 @@ else if (json instanceof Reader) {
136
135
protected <T > T fromJson (Object json , JavaType type ) throws IOException {
137
136
try {
138
137
if (json instanceof String ) {
139
- return this .objectMapper .readValue ((String ) json , type );
138
+ return this .jsonMapper .readValue ((String ) json , type );
140
139
}
141
140
else if (json instanceof byte []) {
142
- return this .objectMapper .readValue ((byte []) json , type );
141
+ return this .jsonMapper .readValue ((byte []) json , type );
143
142
}
144
143
else if (json instanceof File ) {
145
- return this .objectMapper .readValue ((File ) json , type );
144
+ return this .jsonMapper .readValue ((File ) json , type );
146
145
}
147
146
else if (json instanceof URL ) {
148
- return this .objectMapper .readValue ((URL ) json , type );
147
+ return this .jsonMapper .readValue ((URL ) json , type );
149
148
}
150
149
else if (json instanceof InputStream ) {
151
- return this .objectMapper .readValue ((InputStream ) json , type );
150
+ return this .jsonMapper .readValue ((InputStream ) json , type );
152
151
}
153
152
else if (json instanceof Reader ) {
154
- return this .objectMapper .readValue ((Reader ) json , type );
153
+ return this .jsonMapper .readValue ((Reader ) json , type );
155
154
}
156
155
else {
157
156
throw new IllegalArgumentException ("'json' argument must be an instance of: " + SUPPORTED_JSON_TYPES
@@ -166,7 +165,7 @@ else if (json instanceof Reader) {
166
165
@ Override
167
166
public <T > T fromJson (JsonParser parser , Type valueType ) throws IOException {
168
167
try {
169
- return this .objectMapper .readValue (parser , constructType (valueType ));
168
+ return this .jsonMapper .readValue (parser , constructType (valueType ));
170
169
}
171
170
catch (JacksonException e ) {
172
171
throw new IOException (e );
@@ -183,19 +182,19 @@ protected JavaType extractJavaType(Map<String, Object> javaTypes) {
183
182
184
183
JavaType contentClassType = this .createJavaType (javaTypes , JsonHeaders .CONTENT_TYPE_ID );
185
184
if (classType .getKeyType () == null ) {
186
- return this .objectMapper .getTypeFactory ()
185
+ return this .jsonMapper .getTypeFactory ()
187
186
.constructCollectionType ((Class <? extends Collection <?>>) classType .getRawClass (),
188
187
contentClassType );
189
188
}
190
189
191
190
JavaType keyClassType = createJavaType (javaTypes , JsonHeaders .KEY_TYPE_ID );
192
- return this .objectMapper .getTypeFactory ()
191
+ return this .jsonMapper .getTypeFactory ()
193
192
.constructMapType ((Class <? extends Map <?, ?>>) classType .getRawClass (), keyClassType , contentClassType );
194
193
}
195
194
196
195
@ Override
197
196
protected JavaType constructType (Type type ) {
198
- return this .objectMapper .constructType (type );
197
+ return this .jsonMapper .constructType (type );
199
198
}
200
199
201
200
}
0 commit comments