Skip to content

Commit 5d1ee24

Browse files
committed
AbstractJackson2Decoder#decodeToMono support non-blocking parsing
Signed-off-by: ShenFeng312 <[email protected]>
1 parent 68fce29 commit 5d1ee24

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType
128128
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType,
129129
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
130130

131+
return decodeToFlux(input, elementType, mimeType, hints,null);
132+
}
133+
134+
private Flux<Object> decodeToFlux(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints,@Nullable Boolean tokenizeArrays) {
131135
ObjectMapper mapper = selectObjectMapper(elementType, mimeType);
132136
if (mapper == null) {
133137
return Flux.error(new IllegalStateException("No ObjectMapper for " + elementType));
@@ -138,8 +142,10 @@ public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementTy
138142
forceUseOfBigDecimal = true;
139143
}
140144

141-
boolean tokenizeArrays = (!elementType.isArray() &&
142-
!Collection.class.isAssignableFrom(elementType.resolve(Object.class)));
145+
if (tokenizeArrays == null) {
146+
tokenizeArrays = (!elementType.isArray() &&
147+
!Collection.class.isAssignableFrom(elementType.resolve(Object.class)));
148+
}
143149

144150
Flux<DataBuffer> processed = processInput(input, elementType, mimeType, hints);
145151
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(processed, mapper.getFactory(), mapper,
@@ -188,15 +194,7 @@ protected Flux<DataBuffer> processInput(Publisher<DataBuffer> input, ResolvableT
188194
@Override
189195
public Mono<Object> decodeToMono(Publisher<DataBuffer> input, ResolvableType elementType,
190196
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
191-
192-
return Mono.deferContextual(contextView -> {
193-
194-
Map<String, Object> hintsToUse = contextView.isEmpty() ? hints :
195-
Hints.merge(hints, ContextView.class.getName(), contextView);
196-
197-
return DataBufferUtils.join(input, this.maxInMemorySize).flatMap(dataBuffer ->
198-
Mono.justOrEmpty(decode(dataBuffer, elementType, mimeType, hintsToUse)));
199-
});
197+
return decodeToFlux(input, elementType, mimeType, hints, false).singleOrEmpty();
200198
}
201199

202200
@Override

0 commit comments

Comments
 (0)