提交 a7a88371 编写于 作者: A Arjen Poutsma

Allow for decode method to return null in AbstractJackson2Decoder

Prior to this commit, the decoder did not allow for a null value
returned from the Jackson object reader.

Closes: gh-23935
上级 789f6fc1
......@@ -130,7 +130,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return DataBufferUtils.join(input, this.maxInMemorySize)
.map(dataBuffer -> decode(dataBuffer, elementType, mimeType, hints));
.flatMap(dataBuffer -> Mono.justOrEmpty(decode(dataBuffer, elementType, mimeType, hints)));
}
@Override
......
......@@ -29,6 +29,7 @@ import java.nio.file.Files;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
......@@ -1080,6 +1081,24 @@ class WebClientIntegrationTests {
.verify(Duration.ofSeconds(5));
}
@ParameterizedWebClientTest
void nullJsonResponseShouldBeReadAsEmpty(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response
.setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setBody("null"));
Mono<Map> result = this.webClient.get()
.uri("/null")
.retrieve()
.bodyToMono(Map.class);
StepVerifier.create(result)
.verifyComplete();
}
private void prepareResponse(Consumer<MockResponse> consumer) {
MockResponse response = new MockResponse();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册