1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
55
55
*/
56
56
public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport implements HttpMessageDecoder <Object > {
57
57
58
+ /**
59
+ * Until https://github.com/FasterXML/jackson-core/issues/476 is resolved,
60
+ * we need to ensure buffer recycling is off.
61
+ */
62
+ private final JsonFactory jsonFactory ;
63
+
64
+
58
65
/**
59
66
* Constructor with a Jackson {@link ObjectMapper} to use.
60
67
*/
61
68
protected AbstractJackson2Decoder (ObjectMapper mapper , MimeType ... mimeTypes ) {
62
69
super (mapper , mimeTypes );
70
+ this .jsonFactory = mapper .getFactory ().copy ()
71
+ .disable (JsonFactory .Feature .USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING );
63
72
}
64
73
65
74
@@ -75,24 +84,18 @@ public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType
75
84
public Flux <Object > decode (Publisher <DataBuffer > input , ResolvableType elementType ,
76
85
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
77
86
78
- Flux <TokenBuffer > tokens = tokenize (input , true );
87
+ Flux <TokenBuffer > tokens = Jackson2Tokenizer . tokenize (Flux . from ( input ), this . jsonFactory , true );
79
88
return decodeInternal (tokens , elementType , mimeType , hints );
80
89
}
81
90
82
91
@ Override
83
92
public Mono <Object > decodeToMono (Publisher <DataBuffer > input , ResolvableType elementType ,
84
93
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
85
94
86
- Flux <TokenBuffer > tokens = tokenize (input , false );
95
+ Flux <TokenBuffer > tokens = Jackson2Tokenizer . tokenize (Flux . from ( input ), this . jsonFactory , false );
87
96
return decodeInternal (tokens , elementType , mimeType , hints ).singleOrEmpty ();
88
97
}
89
98
90
- private Flux <TokenBuffer > tokenize (Publisher <DataBuffer > input , boolean tokenizeArrayElements ) {
91
- Flux <DataBuffer > inputFlux = Flux .from (input );
92
- JsonFactory factory = getObjectMapper ().getFactory ();
93
- return Jackson2Tokenizer .tokenize (inputFlux , factory , tokenizeArrayElements );
94
- }
95
-
96
99
private Flux <Object > decodeInternal (Flux <TokenBuffer > tokens , ResolvableType elementType ,
97
100
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
98
101
0 commit comments