@@ -271,38 +271,8 @@ public void toHeaders(Headers source, final Map<String, Object> headers) {
271
271
source .forEach (header -> {
272
272
if (!(header .key ().equals (JSON_TYPES ))) {
273
273
if (jsonTypes != null && jsonTypes .containsKey (header .key ())) {
274
- Class <?> type = Object .class ;
275
274
String requestedType = jsonTypes .get (header .key ());
276
- boolean trusted = false ;
277
- try {
278
- trusted = trusted (requestedType );
279
- if (trusted ) {
280
- type = ClassUtils .forName (requestedType , null );
281
- }
282
- }
283
- catch (Exception e ) {
284
- logger .error (e , () -> "Could not load class for header: " + header .key ());
285
- }
286
- if (String .class .equals (type ) && header .value ().length > 0 && header .value ()[0 ] != '"' ) {
287
- headers .put (header .key (), new String (header .value (), getCharset ()));
288
- }
289
- else {
290
- if (trusted ) {
291
- try {
292
- Object value = decodeValue (header , type );
293
- headers .put (header .key (), value );
294
- }
295
- catch (IOException e ) {
296
- logger .error (e , () ->
297
- "Could not decode json type: " + new String (header .value ()) + " for key: "
298
- + header .key ());
299
- headers .put (header .key (), header .value ());
300
- }
301
- }
302
- else {
303
- headers .put (header .key (), new NonTrustedHeaderType (header .value (), requestedType ));
304
- }
305
- }
275
+ populateJsonValueHeader (header , requestedType , headers );
306
276
}
307
277
else {
308
278
headers .put (header .key (), headerValueToAddIn (header ));
@@ -311,6 +281,40 @@ public void toHeaders(Headers source, final Map<String, Object> headers) {
311
281
});
312
282
}
313
283
284
+ private void populateJsonValueHeader (Header header , String requestedType , Map <String , Object > headers ) {
285
+ Class <?> type = Object .class ;
286
+ boolean trusted = false ;
287
+ try {
288
+ trusted = trusted (requestedType );
289
+ if (trusted ) {
290
+ type = ClassUtils .forName (requestedType , null );
291
+ }
292
+ }
293
+ catch (Exception e ) {
294
+ logger .error (e , () -> "Could not load class for header: " + header .key ());
295
+ }
296
+ if (String .class .equals (type ) && header .value ().length > 0 && header .value ()[0 ] != '"' ) {
297
+ headers .put (header .key (), new String (header .value (), getCharset ()));
298
+ }
299
+ else {
300
+ if (trusted ) {
301
+ try {
302
+ Object value = decodeValue (header , type );
303
+ headers .put (header .key (), value );
304
+ }
305
+ catch (IOException e ) {
306
+ logger .error (e , () ->
307
+ "Could not decode json type: " + new String (header .value ()) + " for key: "
308
+ + header .key ());
309
+ headers .put (header .key (), header .value ());
310
+ }
311
+ }
312
+ else {
313
+ headers .put (header .key (), new NonTrustedHeaderType (header .value (), requestedType ));
314
+ }
315
+ }
316
+ }
317
+
314
318
private Object decodeValue (Header h , Class <?> type ) throws IOException , LinkageError {
315
319
ObjectMapper headerObjectMapper = getObjectMapper ();
316
320
Object value = headerObjectMapper .readValue (h .value (), type );
0 commit comments