From b47491695e7f5ad1d047c7156dd362c4f529630d Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 22 Jan 2018 17:07:38 +0100 Subject: [PATCH] Support array of scalar values in Jackson2Tokenizer Issue: SPR-16407 --- .../http/codec/json/Jackson2Tokenizer.java | 7 ++++--- .../http/codec/json/Jackson2TokenizerTests.java | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java index 0cd3b78aed..696b559f4f 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -173,8 +173,9 @@ class Jackson2Tokenizer { this.tokenBuffer.copyCurrentEvent(this.parser); } - if ((token == JsonToken.END_OBJECT && this.objectDepth == 0 && (this.arrayDepth == 1 || this.arrayDepth == 0)) || - (token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) { + if (this.objectDepth == 0 && + (this.arrayDepth == 0 || this.arrayDepth == 1) && + (token == JsonToken.END_OBJECT || token.isScalarValue())) { result.add(this.tokenBuffer); this.tokenBuffer = new TokenBuffer(this.parser); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java index 572a1de90e..2d76831162 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -168,6 +168,10 @@ public class Jackson2TokenizerTests extends AbstractDataBufferAllocatingTestCase testTokenize(asList("12.", "34") ,singletonList("12.34"), true); + + // SPR-16407 + testTokenize(asList("[1", ",2,", "3]"), + asList("1", "2", "3"), true); } private void testTokenize(List source, List expected, boolean tokenizeArrayElements) { @@ -175,7 +179,7 @@ public class Jackson2TokenizerTests extends AbstractDataBufferAllocatingTestCase .map(this::stringBuffer); Flux tokenBufferFlux = - Jackson2Tokenizer.tokenize(sourceFlux, jsonFactory, tokenizeArrayElements); + Jackson2Tokenizer.tokenize(sourceFlux, this.jsonFactory, tokenizeArrayElements); Flux result = tokenBufferFlux .map(tokenBuffer -> {