Skip to content

Commit 14ccb38

Browse files
committed
Handle nested w/o top-level array in Jackson2JsonTokenizer
Issue: SPR-15803
1 parent bd0de70 commit 14ccb38

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws
152152
}
153153

154154
private boolean isTopLevelArrayToken(JsonToken token) {
155-
return (token == JsonToken.START_ARRAY && this.arrayDepth == 1) ||
156-
(token == JsonToken.END_ARRAY && this.arrayDepth == 0);
155+
return this.objectDepth == 0 && ((token == JsonToken.START_ARRAY && this.arrayDepth == 1) ||
156+
(token == JsonToken.END_ARRAY && this.arrayDepth == 0));
157157
}
158158

159159
public void endOfInput() {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void createParser() throws IOException {
5757
}
5858

5959
@Test
60-
public void noTokenizeArrayElements() {
60+
public void doNotTokenizeArrayElements() {
6161
this.tokenizer = new Jackson2Tokenizer(this.jsonParser, false);
6262

6363
testTokenize(
@@ -116,7 +116,7 @@ public void tokenizeArrayElements() {
116116
asList("{\"foo\": \"bar\"}",
117117
"{\"foo\": \"baz\"}"));
118118

119-
// SPR-15803
119+
// SPR-15803: nested array
120120
testTokenize(
121121
singletonList("[" +
122122
"{\"id\":\"0\",\"start\":[-999999999,1,1],\"end\":[999999999,12,31]}," +
@@ -129,6 +129,11 @@ public void tokenizeArrayElements() {
129129
"{\"id\":\"2\",\"start\":[-999999999,1,1],\"end\":[999999999,12,31]}")
130130
);
131131

132+
// SPR-15803: nested array, no top-level array
133+
testTokenize(
134+
singletonList("{\"speakerIds\":[\"tastapod\"],\"language\":\"ENGLISH\"}"),
135+
singletonList("{\"speakerIds\":[\"tastapod\"],\"language\":\"ENGLISH\"}"));
136+
132137
testTokenize(
133138
asList("[{\"foo\": \"foofoo\", \"bar\"",
134139
": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"),

0 commit comments

Comments
 (0)