Skip to content

Commit

Permalink
Upgrade to Jackson 2.14.0-rc2
Browse files Browse the repository at this point in the history
This commit upgrades Jackson to 2.14.0-rc2, and uses the new
ByteBufferFeeder in Jackson2Tokenizer.

Unfortunately, because of FasterXML/jackson-core#478,
we had to change the CompilerConventions to suppress class file warnings.

Closes gh-29343
  • Loading branch information
poutsma committed Oct 19, 2022
1 parent aa776e4 commit f99c02f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
Expand Up @@ -23,7 +23,6 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.compile.JavaCompile;

Expand All @@ -42,7 +41,7 @@ public class CompilerConventions {

static {
List<String> commonCompilerArgs = Arrays.asList(
"-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
"-Xlint:serial", "-Xlint:cast", "-Xlint:-classfile", "-Xlint:dep-ann",
"-Xlint:divzero", "-Xlint:empty", "-Xlint:finally", "-Xlint:overrides",
"-Xlint:path", "-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options",
"-parameters"
Expand Down
2 changes: 1 addition & 1 deletion framework-platform/framework-platform.gradle
Expand Up @@ -7,7 +7,7 @@ javaPlatform {
}

dependencies {
api(platform("com.fasterxml.jackson:jackson-bom:2.13.4"))
api(platform("com.fasterxml.jackson:jackson-bom:2.14.0-rc2"))
api(platform("io.micrometer:micrometer-bom:1.10.0-RC1"))
api(platform("io.netty:netty-bom:4.1.84.Final"))
api(platform("io.netty:netty5-bom:5.0.0.Alpha5"))
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.springframework.http.codec.json;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
Expand All @@ -26,10 +27,13 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.async.ByteArrayFeeder;
import com.fasterxml.jackson.core.async.ByteBufferFeeder;
import com.fasterxml.jackson.core.async.NonBlockingInputFeeder;
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.dataformat.smile.SmileFactory;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;

Expand All @@ -54,6 +58,8 @@ final class Jackson2Tokenizer {

private final DeserializationContext deserializationContext;

private final NonBlockingInputFeeder inputFeeder;

private final boolean tokenizeArrayElements;

private final boolean forceUseOfBigDecimal;
Expand All @@ -69,33 +75,32 @@ final class Jackson2Tokenizer {
private TokenBuffer tokenBuffer;


// TODO: change to ByteBufferFeeder when supported by Jackson
// See https://github.com/FasterXML/jackson-core/issues/478
private final ByteArrayFeeder inputFeeder;


private Jackson2Tokenizer(JsonParser parser, DeserializationContext deserializationContext,
boolean tokenizeArrayElements, boolean forceUseOfBigDecimal, int maxInMemorySize) {

this.parser = parser;
this.deserializationContext = deserializationContext;
this.inputFeeder = this.parser.getNonBlockingInputFeeder();
this.tokenizeArrayElements = tokenizeArrayElements;
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
this.maxInMemorySize = maxInMemorySize;
this.tokenBuffer = createToken();
}



private List<TokenBuffer> tokenize(DataBuffer dataBuffer) {
int bufferSize = dataBuffer.readableByteCount();
byte[] bytes = new byte[bufferSize];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);

try {
this.inputFeeder.feedInput(bytes, 0, bytes.length);
int bufferSize = dataBuffer.readableByteCount();
if (this.inputFeeder instanceof ByteBufferFeeder byteBufferFeeder) {
ByteBuffer byteBuffer = dataBuffer.toByteBuffer();
byteBufferFeeder.feedInput(byteBuffer);
}
else if (this.inputFeeder instanceof ByteArrayFeeder byteArrayFeeder) {
byte[] bytes = new byte[bufferSize];
dataBuffer.read(bytes);
byteArrayFeeder.feedInput(bytes, 0, bufferSize);
}
List<TokenBuffer> result = parseTokenBufferFlux();
assertInMemorySize(bufferSize, result);
return result;
Expand All @@ -106,6 +111,9 @@ private List<TokenBuffer> tokenize(DataBuffer dataBuffer) {
catch (IOException ex) {
throw Exceptions.propagate(ex);
}
finally {
DataBufferUtils.release(dataBuffer);
}
}

private Flux<TokenBuffer> endOfInput() {
Expand Down Expand Up @@ -232,7 +240,14 @@ public static Flux<TokenBuffer> tokenize(Flux<DataBuffer> dataBuffers, JsonFacto
ObjectMapper objectMapper, boolean tokenizeArrays, boolean forceUseOfBigDecimal, int maxInMemorySize) {

try {
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
JsonParser parser;
if (jsonFactory.getFormatName().equals(SmileFactory.FORMAT_NAME_SMILE)) {
// ByteBufferFeeder is not supported for Smile
parser = jsonFactory.createNonBlockingByteArrayParser();
}
else {
parser = jsonFactory.createNonBlockingByteBufferParser();
}
DeserializationContext context = objectMapper.getDeserializationContext();
if (context instanceof DefaultDeserializationContext) {
context = ((DefaultDeserializationContext) context).createInstance(
Expand Down

1 comment on commit f99c02f

@poutsma
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message should have linked to FasterXML/jackson-core#824.

Please sign in to comment.