From 4021d239ab15dfd119d248c9e830ed2f2f935985 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Wed, 14 Dec 2016 14:38:19 +0100 Subject: [PATCH] Fix JsonObjectDecoder with '[' starting chunk Issue: SPR-15013 --- .../http/codec/json/JsonObjectDecoder.java | 3 --- .../http/codec/json/JsonObjectDecoderTests.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java index 93f6f47599..e90db76855 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java @@ -212,9 +212,6 @@ class JsonObjectDecoder extends AbstractDecoder { } } - if (this.input.readableBytes() == 0) { - this.index = 0; - } return Flux.fromIterable(chunks); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java index 24f26e1f20..375da5260f 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java @@ -106,6 +106,19 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase .expectNext("{\"foo\": \"baz\"}") .expectComplete() .verify(); + + // SPR-15013 + source = Flux.just(stringBuffer("["), stringBuffer("{\"id\":1,\"name\":\"Robert\"}"), + stringBuffer(","), stringBuffer("{\"id\":2,\"name\":\"Raide\"}"), + stringBuffer(","), stringBuffer("{\"id\":3,\"name\":\"Ford\"}"), + stringBuffer("]")); + output = decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString); + StepVerifier.create(output) + .expectNext("{\"id\":1,\"name\":\"Robert\"}") + .expectNext("{\"id\":2,\"name\":\"Raide\"}") + .expectNext("{\"id\":3,\"name\":\"Ford\"}") + .expectComplete() + .verify(); }