Skip to content

Commit b474916

Browse files
committed
Support array of scalar values in Jackson2Tokenizer
Issue: SPR-16407
1 parent 9d0e62e commit b474916

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -173,8 +173,9 @@ private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws
173173
this.tokenBuffer.copyCurrentEvent(this.parser);
174174
}
175175

176-
if ((token == JsonToken.END_OBJECT && this.objectDepth == 0 && (this.arrayDepth == 1 || this.arrayDepth == 0)) ||
177-
(token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
176+
if (this.objectDepth == 0 &&
177+
(this.arrayDepth == 0 || this.arrayDepth == 1) &&
178+
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
178179
result.add(this.tokenBuffer);
179180
this.tokenBuffer = new TokenBuffer(this.parser);
180181
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -168,14 +168,18 @@ public void tokenizeArrayElements() {
168168

169169
testTokenize(asList("12.", "34")
170170
,singletonList("12.34"), true);
171+
172+
// SPR-16407
173+
testTokenize(asList("[1", ",2,", "3]"),
174+
asList("1", "2", "3"), true);
171175
}
172176

173177
private void testTokenize(List<String> source, List<String> expected, boolean tokenizeArrayElements) {
174178
Flux<DataBuffer> sourceFlux = Flux.fromIterable(source)
175179
.map(this::stringBuffer);
176180

177181
Flux<TokenBuffer> tokenBufferFlux =
178-
Jackson2Tokenizer.tokenize(sourceFlux, jsonFactory, tokenizeArrayElements);
182+
Jackson2Tokenizer.tokenize(sourceFlux, this.jsonFactory, tokenizeArrayElements);
179183

180184
Flux<String> result = tokenBufferFlux
181185
.map(tokenBuffer -> {

0 commit comments

Comments
 (0)