Skip to content

Commit

Permalink
Assign TokenBuffer field with createToken() result
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Feb 25, 2020
1 parent 6db20eb commit d72c90c
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferLimitException;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;

/**
* {@link Function} to transform a JSON stream of arbitrary size, byte array
Expand Down Expand Up @@ -67,7 +66,6 @@ final class Jackson2Tokenizer {

private int byteCount;

@Nullable // yet initialized by calling createToken() in the constructor
private TokenBuffer tokenBuffer;


Expand All @@ -85,7 +83,7 @@ private Jackson2Tokenizer(JsonParser parser, DeserializationContext deserializat
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
this.maxInMemorySize = maxInMemorySize;
createToken();
this.tokenBuffer = createToken();
}


Expand Down Expand Up @@ -176,9 +174,8 @@ private void processTokenNormal(JsonToken token, List<TokenBuffer> result) throw

if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}

}

private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
Expand All @@ -189,13 +186,14 @@ private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}
}

private void createToken() {
this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
this.tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
private TokenBuffer createToken() {
TokenBuffer tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
return tokenBuffer;
}

private boolean isTopLevelArrayToken(JsonToken token) {
Expand Down Expand Up @@ -233,8 +231,8 @@ private void raiseLimitException() {
* @param objectMapper the current mapper instance
* @param tokenizeArrays if {@code true} and the "top level" JSON object is
* an array, each element is returned individually immediately after it is received
* @param forceUseOfBigDecimal if {@code true}, any floating point values encountered in source will use
* {@link java.math.BigDecimal}
* @param forceUseOfBigDecimal if {@code true}, any floating point values encountered
* in source will use {@link java.math.BigDecimal}
* @param maxInMemorySize maximum memory size
* @return the resulting token buffers
*/
Expand All @@ -248,8 +246,8 @@ public static Flux<TokenBuffer> tokenize(Flux<DataBuffer> dataBuffers, JsonFacto
context = ((DefaultDeserializationContext) context).createInstance(
objectMapper.getDeserializationConfig(), parser, objectMapper.getInjectableValues());
}
Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, context, tokenizeArrays, forceUseOfBigDecimal,
maxInMemorySize);
Jackson2Tokenizer tokenizer =
new Jackson2Tokenizer(parser, context, tokenizeArrays, forceUseOfBigDecimal, maxInMemorySize);
return dataBuffers.concatMapIterable(tokenizer::tokenize).concatWith(tokenizer.endOfInput());
}
catch (IOException ex) {
Expand Down

0 comments on commit d72c90c

Please sign in to comment.