|
|
|
@ -27,6 +27,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.core.JsonToken; |
|
|
|
import com.fasterxml.jackson.core.JsonToken; |
|
|
|
import com.fasterxml.jackson.core.async.ByteArrayFeeder; |
|
|
|
import com.fasterxml.jackson.core.async.ByteArrayFeeder; |
|
|
|
import com.fasterxml.jackson.databind.DeserializationContext; |
|
|
|
import com.fasterxml.jackson.databind.DeserializationContext; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext; |
|
|
|
import com.fasterxml.jackson.databind.util.TokenBuffer; |
|
|
|
import com.fasterxml.jackson.databind.util.TokenBuffer; |
|
|
|
import reactor.core.Exceptions; |
|
|
|
import reactor.core.Exceptions; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
@ -177,16 +179,22 @@ final class Jackson2Tokenizer { |
|
|
|
* Tokenize the given {@code Flux<DataBuffer>} into {@code Flux<TokenBuffer>}. |
|
|
|
* Tokenize the given {@code Flux<DataBuffer>} into {@code Flux<TokenBuffer>}. |
|
|
|
* @param dataBuffers the source data buffers |
|
|
|
* @param dataBuffers the source data buffers |
|
|
|
* @param jsonFactory the factory to use |
|
|
|
* @param jsonFactory the factory to use |
|
|
|
|
|
|
|
* @param objectMapper the current mapper instance |
|
|
|
* @param tokenizeArrayElements if {@code true} and the "top level" JSON object is |
|
|
|
* @param tokenizeArrayElements if {@code true} and the "top level" JSON object is |
|
|
|
* an array, each element is returned individually immediately after it is received |
|
|
|
* an array, each element is returned individually immediately after it is received |
|
|
|
* @return the resulting token buffers |
|
|
|
* @return the resulting token buffers |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Flux<TokenBuffer> tokenize(Flux<DataBuffer> dataBuffers, JsonFactory jsonFactory, |
|
|
|
public static Flux<TokenBuffer> tokenize(Flux<DataBuffer> dataBuffers, JsonFactory jsonFactory, |
|
|
|
DeserializationContext deserializationContext, boolean tokenizeArrayElements) { |
|
|
|
ObjectMapper objectMapper, boolean tokenizeArrayElements) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser(); |
|
|
|
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser(); |
|
|
|
Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, deserializationContext, tokenizeArrayElements); |
|
|
|
DeserializationContext context = objectMapper.getDeserializationContext(); |
|
|
|
|
|
|
|
if (context instanceof DefaultDeserializationContext) { |
|
|
|
|
|
|
|
context = ((DefaultDeserializationContext) context).createInstance( |
|
|
|
|
|
|
|
objectMapper.getDeserializationConfig(), parser, objectMapper.getInjectableValues()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, context, tokenizeArrayElements); |
|
|
|
return dataBuffers.concatMapIterable(tokenizer::tokenize).concatWith(tokenizer.endOfInput()); |
|
|
|
return dataBuffers.concatMapIterable(tokenizer::tokenize).concatWith(tokenizer.endOfInput()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IOException ex) { |
|
|
|
catch (IOException ex) { |
|
|
|
|