Skip to content

Commit cee8b52

Browse files
committed
Merge branch '6.1.x'
2 parents 9a76157 + 912c067 commit cee8b52

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.core.io.buffer.DataBuffer;
4545
import org.springframework.core.io.buffer.DataBufferLimitException;
4646
import org.springframework.core.io.buffer.DataBufferUtils;
47+
import org.springframework.core.io.buffer.PooledDataBuffer;
4748
import org.springframework.core.log.LogFormatUtils;
4849
import org.springframework.http.codec.HttpMessageDecoder;
4950
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -162,7 +163,8 @@ public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementTy
162163
catch (IOException ex) {
163164
sink.error(processException(ex));
164165
}
165-
});
166+
})
167+
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
166168
});
167169
}
168170

spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void canDecodeWithObjectMapperRegistrationForType() {
117117
}
118118

119119
@Test // SPR-15866
120-
public void canDecodeWithProvidedMimeType() {
120+
void canDecodeWithProvidedMimeType() {
121121
MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8);
122122
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(new ObjectMapper(), textJavascript);
123123

@@ -239,15 +239,15 @@ void invalidData() {
239239
}
240240

241241
@Test // gh-22042
242-
public void decodeWithNullLiteral() {
242+
void decodeWithNullLiteral() {
243243
Flux<Object> result = this.decoder.decode(Flux.concat(stringBuffer("null")),
244244
ResolvableType.forType(Pojo.class), MediaType.APPLICATION_JSON, Collections.emptyMap());
245245

246246
StepVerifier.create(result).expectComplete().verify();
247247
}
248248

249249
@Test // gh-27511
250-
public void noDefaultConstructor() {
250+
void noDefaultConstructor() {
251251
Flux<DataBuffer> input = Flux.from(stringBuffer("{\"property1\":\"foo\",\"property2\":\"bar\"}"));
252252

253253
testDecode(input, BeanWithNoDefaultConstructor.class, step -> step
@@ -268,7 +268,7 @@ void codecException() {
268268
}
269269

270270
@Test // SPR-15975
271-
public void customDeserializer() {
271+
void customDeserializer() {
272272
Mono<DataBuffer> input = stringBuffer("{\"test\": 1}");
273273

274274
testDecode(input, TestObject.class, step -> step
@@ -289,7 +289,7 @@ void bigDecimalFlux() {
289289

290290
@Test
291291
@SuppressWarnings("unchecked")
292-
public void decodeNonUtf8Encoding() {
292+
void decodeNonUtf8Encoding() {
293293
Mono<DataBuffer> input = stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.UTF_16);
294294
ResolvableType type = ResolvableType.forType(new ParameterizedTypeReference<Map<String, String>>() {});
295295

@@ -302,7 +302,7 @@ public void decodeNonUtf8Encoding() {
302302

303303
@Test
304304
@SuppressWarnings("unchecked")
305-
public void decodeNonUnicode() {
305+
void decodeNonUnicode() {
306306
Flux<DataBuffer> input = Flux.concat(stringBuffer("{\"føø\":\"bår\"}", StandardCharsets.ISO_8859_1));
307307
ResolvableType type = ResolvableType.forType(new ParameterizedTypeReference<Map<String, String>>() {});
308308

@@ -315,7 +315,7 @@ public void decodeNonUnicode() {
315315

316316
@Test
317317
@SuppressWarnings("unchecked")
318-
public void decodeMonoNonUtf8Encoding() {
318+
void decodeMonoNonUtf8Encoding() {
319319
Mono<DataBuffer> input = stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.UTF_16);
320320
ResolvableType type = ResolvableType.forType(new ParameterizedTypeReference<Map<String, String>>() {});
321321

@@ -328,7 +328,7 @@ public void decodeMonoNonUtf8Encoding() {
328328

329329
@Test
330330
@SuppressWarnings("unchecked")
331-
public void decodeAscii() {
331+
void decodeAscii() {
332332
Flux<DataBuffer> input = Flux.concat(stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.US_ASCII));
333333
ResolvableType type = ResolvableType.forType(new ParameterizedTypeReference<Map<String, String>>() {});
334334

@@ -339,6 +339,15 @@ public void decodeAscii() {
339339
null);
340340
}
341341

342+
@Test
343+
void cancelWhileDecoding() {
344+
Flux<DataBuffer> input = Flux.just(
345+
stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},").block(),
346+
stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]").block());
347+
348+
testDecodeCancel(input, ResolvableType.forClass(Pojo.class), null, null);
349+
}
350+
342351

343352
private Mono<DataBuffer> stringBuffer(String value) {
344353
return stringBuffer(value, StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)