Skip to content

Commit

Permalink
Merge pull request #30751 from vespa-engine/renovate/jackson2.vespa.v…
Browse files Browse the repository at this point in the history
…ersion

Update jackson2.vespa.version to v2.17.0
  • Loading branch information
baldersheim authored May 6, 2024
2 parents 1891085 + 1d26b94 commit 2dc47f1
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void consumeValuesArray() throws IOException {
private void consumeTopObject() throws IOException {
for (var cur = parser.nextToken(); cur != JsonToken.END_OBJECT; cur = parser.nextToken()) {
assertCurrentTokenIs(JsonToken.FIELD_NAME);
String fieldName = parser.getCurrentName();
String fieldName = parser.currentName();
switch (fieldName) {
case FIELD_TYPE -> consumeTypeField();
case FIELD_VALUES -> consumeValuesField();
Expand Down Expand Up @@ -189,7 +189,7 @@ private void consumeSimpleMappedObject() throws IOException {
}
for (var cur = parser.nextToken(); cur != JsonToken.END_OBJECT; cur = parser.nextToken()) {
assertCurrentTokenIs(JsonToken.FIELD_NAME);
validateNumeric(parser.getCurrentName(), parser.nextToken());
validateNumeric(parser.currentName(), parser.nextToken());
}
}

Expand All @@ -199,7 +199,7 @@ private void validateLiteralFormCell() throws IOException {
boolean seenValue = false;
for (int i = 0; i < 2; i++) {
assertNextTokenIs(JsonToken.FIELD_NAME);
String fieldName = parser.getCurrentName();
String fieldName = parser.currentName();
switch (fieldName) {
case FIELD_ADDRESS -> {
validateTensorAddress(new HashSet<>(tensorDimensions.keySet()));
Expand Down Expand Up @@ -228,13 +228,13 @@ private void validateTensorAddress(Set<String> cellDimensions) throws IOExceptio
// Iterate within the address key, value pairs
while ((parser.nextToken() != JsonToken.END_OBJECT)) {
assertCurrentTokenIs(JsonToken.FIELD_NAME);
String dimensionName = parser.getCurrentName();
String dimensionName = parser.currentName();
TensorType.Dimension dimension = tensorDimensions.get(dimensionName);
if (dimension == null) {
throw new InvalidConstantTensorException(parser, String.format("Tensor dimension '%s' does not exist", parser.getCurrentName()));
throw new InvalidConstantTensorException(parser, String.format("Tensor dimension '%s' does not exist", dimensionName));
}
if (!cellDimensions.contains(dimensionName)) {
throw new InvalidConstantTensorException(parser, String.format("Duplicate tensor dimension '%s'", parser.getCurrentName()));
throw new InvalidConstantTensorException(parser, String.format("Duplicate tensor dimension '%s'", dimensionName));
}
cellDimensions.remove(dimensionName);
validateLabel(dimension);
Expand Down Expand Up @@ -300,7 +300,7 @@ private void validateNumeric(String where, JsonToken token) throws IOException {
}

private void assertCurrentTokenIs(JsonToken wantedToken) {
assertTokenIs(parser.getCurrentToken(), wantedToken);
assertTokenIs(parser.currentToken(), wantedToken);
}

private void assertNextTokenIs(JsonToken wantedToken) throws IOException {
Expand All @@ -316,11 +316,11 @@ private void assertTokenIs(JsonToken token, JsonToken wantedToken) {
static class InvalidConstantTensorException extends IllegalArgumentException {

InvalidConstantTensorException(JsonParser parser, String message) {
super(message + " " + parser.getCurrentLocation().toString());
super(message + " " + parser.currentLocation().toString());
}

InvalidConstantTensorException(JsonParser parser, Exception base) {
super("Failed to parse JSON stream " + parser.getCurrentLocation().toString(), base);
super("Failed to parse JSON stream " + parser.currentLocation().toString(), base);
}

InvalidConstantTensorException(IOException base) {
Expand Down Expand Up @@ -412,7 +412,7 @@ private void consumeBlocksArray() throws IOException {
boolean seenValues = false;
for (int i = 0; i < 2; i++) {
assertNextTokenIs(JsonToken.FIELD_NAME);
String fieldName = parser.getCurrentName();
String fieldName = parser.currentName();
switch (fieldName) {
case FIELD_ADDRESS -> {
validateTensorAddress(new HashSet<>(mappedDims));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Map<String, String> parse() {
}

void parse(Map<String, String> map, String parent) throws IOException {
for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parent + parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parent + parser.currentName();
JsonToken token = parser.nextToken();
if ((token == JsonToken.VALUE_STRING) ||
(token == JsonToken.VALUE_NUMBER_FLOAT) ||
Expand All @@ -89,9 +89,9 @@ void parse(Map<String, String> map, String parent) throws IOException {
}

private String skipChildren(JsonParser parser, byte [] input) throws IOException {
JsonLocation start = parser.getCurrentLocation();
JsonLocation start = parser.currentLocation();
parser.skipChildren();
JsonLocation end = parser.getCurrentLocation();
JsonLocation end = parser.currentLocation();
int offset = (int)start.getByteOffset() - 1;
return new String(input, offset, (int)(end.getByteOffset() - offset), StandardCharsets.UTF_8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ void testThatTheJsonValidatorCanCatchErrors() {
+ "}";
assertEquals(
"Unexpected character ('a' (code 97)): was expecting comma to separate Object entries\n" +
" at [Source: (String)\"{ \"root\": { \"invalidvalue\": 1adsf, }}\"; line: 1, column: 41]",
" at [Source: (String)\"{ \"root\": { \"invalidvalue\": 1adsf, }}\"; line: 1, column: 40]",
validateJSON(json));
}

Expand Down
2 changes: 1 addition & 1 deletion dependency-versions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<guava.vespa.version>33.2.0-jre</guava.vespa.version>
<guice.vespa.version>6.0.0</guice.vespa.version>
<j2objc-annotations.vespa.version>3.0.0</j2objc-annotations.vespa.version>
<jackson2.vespa.version>2.16.2</jackson2.vespa.version>
<jackson2.vespa.version>2.17.1</jackson2.vespa.version>
<jackson-databind.vespa.version>${jackson2.vespa.version}</jackson-databind.vespa.version>
<jakarta.inject.vespa.version>2.0.1</jakarta.inject.vespa.version>
<javax.activation-api.vespa.version>1.2.0</javax.activation-api.vespa.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ParsedDocumentOperation readSingleDocumentStreaming(DocumentOperationType
String condition = null;
ParsedDocumentOperation operation = null;
while (JsonToken.END_OBJECT != parser.nextValue()) {
switch (parser.getCurrentName()) {
switch (parser.currentName()) {
case FIELDS -> {
documentParseInfo.fieldsBuffer = new LazyTokenBuffer(parser);
VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader(typeManager.getIgnoreUndefinedFields());
Expand Down Expand Up @@ -177,7 +177,7 @@ public DocumentOperation next() {
state = END_OF_FEED;
throw new IllegalArgumentException(r);
}
if ( ! documentParseInfo.isPresent()) {
if (documentParseInfo.isEmpty()) {
state = END_OF_FEED;
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void advance() {
public Supplier<Token> lookahead() {
return new Supplier<>() {
int localNesting = nesting();
Supplier<Token> buffered = LazyTokenBuffer.super.lookahead();
final Supplier<Token> buffered = LazyTokenBuffer.super.lookahead();
@Override public Token get() {
if (localNesting == 0)
return null;
Expand All @@ -54,7 +54,7 @@ private Token nextToken() {
JsonToken token = parser.nextValue();
if (token == null)
throw new IllegalStateException("no more JSON tokens");
return new Token(token, parser.getCurrentName(), parser.getText());
return new Token(token, parser.currentName(), parser.getText());
}
catch (IOException e) {
throw new IllegalArgumentException("failed reading document JSON", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int nestingOffset(JsonToken token) {
}

int addFromParser(JsonParser tokens) throws IOException {
add(tokens.currentToken(), tokens.getCurrentName(), tokens.getText());
add(tokens.currentToken(), tokens.currentName(), tokens.getText());
return nestingOffset(tokens.currentToken());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Optional<DocumentParseInfo> parse(Optional<DocumentId> documentIdArg) thr
private boolean parseOneItem(DocumentParseInfo documentParseInfo, boolean docIdAndOperationIsSetExternally) throws IOException {
parser.nextValue();
processIndent();
if (parser.getCurrentName() == null) return false;
if (parser.currentName() == null) return false;
if (indentLevel == 1L) {
handleIdentLevelOne(documentParseInfo, docIdAndOperationIsSetExternally);
} else if (indentLevel == 2L) {
Expand All @@ -85,17 +85,18 @@ private void processIndent() {

private void handleIdentLevelOne(DocumentParseInfo documentParseInfo, boolean docIdAndOperationIsSetExternally)
throws IOException {
JsonToken currentToken = parser.getCurrentToken();
JsonToken currentToken = parser.currentToken();
String currentName = parser.currentName();
if ((currentToken == JsonToken.VALUE_TRUE || currentToken == JsonToken.VALUE_FALSE) &&
CREATE_IF_NON_EXISTENT.equals(parser.getCurrentName())) {
CREATE_IF_NON_EXISTENT.equals(currentName)) {
documentParseInfo.create = Optional.of(currentToken == JsonToken.VALUE_TRUE);
} else if (currentToken == JsonToken.VALUE_STRING && CONDITION.equals(parser.getCurrentName())) {
} else if (currentToken == JsonToken.VALUE_STRING && CONDITION.equals(currentName)) {
documentParseInfo.condition = Optional.of(parser.getText());
} else if (currentToken == JsonToken.VALUE_STRING) {
// Value is expected to be set in the header not in the document. Ignore any unknown field
// as well.
if (! docIdAndOperationIsSetExternally) {
documentParseInfo.operationType = operationNameToOperationType(parser.getCurrentName());
documentParseInfo.operationType = operationNameToOperationType(currentName);
documentParseInfo.documentId = new DocumentId(parser.getText());
}
}
Expand All @@ -104,7 +105,7 @@ private void handleIdentLevelOne(DocumentParseInfo documentParseInfo, boolean do
private void handleIdentLevelTwo(DocumentParseInfo documentParseInfo) {
try {
// "fields" opens a dictionary and is therefore on level two which might be surprising.
if (parser.currentToken() == JsonToken.START_OBJECT && FIELDS.equals(parser.getCurrentName())) {
if (parser.currentToken() == JsonToken.START_OBJECT && FIELDS.equals(parser.currentName())) {
documentParseInfo.fieldsBuffer.bufferObject(parser);
processIndent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private static void parse(JsonParser parser, Collector consumer) throws IOExcept
throw new IOException("Expected start of object, got " + parser.currentToken());
}

for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.currentName();
JsonToken token = parser.nextToken();
if (fieldName.equals("metrics")) {
parseMetrics(parser, consumer);
Expand All @@ -67,12 +67,12 @@ private static void parse(JsonParser parser, Collector consumer) throws IOExcept
}

static private Instant parseSnapshot(JsonParser parser) throws IOException {
if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
if (parser.currentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected start of 'snapshot' object, got " + parser.currentToken());
}
Instant timestamp = Instant.now();
for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.currentName();
JsonToken token = parser.nextToken();
if (fieldName.equals("to")) {
timestamp = Instant.ofEpochSecond(parser.getLongValue());
Expand All @@ -88,12 +88,12 @@ static private Instant parseSnapshot(JsonParser parser) throws IOException {

// 'metrics' object with 'snapshot' and 'values' arrays
static private void parseMetrics(JsonParser parser, Collector consumer) throws IOException {
if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
if (parser.currentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected start of 'metrics' object, got " + parser.currentToken());
}
Instant timestamp = Instant.now();
for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.currentName();
JsonToken token = parser.nextToken();
if (fieldName.equals("snapshot")) {
timestamp = parseSnapshot(parser);
Expand All @@ -109,7 +109,7 @@ static private void parseMetrics(JsonParser parser, Collector consumer) throws I

// 'values' array
static private void parseMetricValues(JsonParser parser, Instant timestamp, Collector consumer) throws IOException {
if (parser.getCurrentToken() != JsonToken.START_ARRAY) {
if (parser.currentToken() != JsonToken.START_ARRAY) {
throw new IOException("Expected start of 'metrics:values' array, got " + parser.currentToken());
}

Expand All @@ -126,8 +126,8 @@ static private void handleValue(JsonParser parser, Instant timestamp, Collector
String description = "";
Map<DimensionId, String> dim = Map.of();
List<Map.Entry<String, Number>> values = List.of();
for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.currentName();
JsonToken token = parser.nextToken();
switch (fieldName) {
case "name" -> name = parser.getText();
Expand All @@ -154,8 +154,8 @@ private static Map<DimensionId, String> parseDimensions(JsonParser parser,

Set<Dimension> dimensions = new HashSet<>();

for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.currentName();
JsonToken token = parser.nextToken();

if (token == JsonToken.VALUE_STRING){
Expand All @@ -180,17 +180,16 @@ static Dimension of(String id, String value) {

private static List<Map.Entry<String, Number>> parseValues(JsonParser parser) throws IOException {
List<Map.Entry<String, Number>> metrics = new ArrayList<>();
for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String fieldName = parser.getCurrentName();
for (parser.nextToken(); parser.currentToken() != JsonToken.END_OBJECT; parser.nextToken()) {
String metricName = parser.currentName();
JsonToken token = parser.nextToken();
String metricName = fieldName;
if (token == JsonToken.VALUE_NUMBER_INT) {
metrics.add(Map.entry(metricName, parser.getLongValue()));
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
double value = parser.getValueAsDouble();
metrics.add(Map.entry(metricName, value == ZERO_DOUBLE ? ZERO_DOUBLE : value));
} else {
throw new IllegalArgumentException("Value for aggregator '" + fieldName + "' is not a number");
throw new IllegalArgumentException("Value for aggregator '" + metricName + "' is not a number");
}
}
return metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public boolean canImport(String modelPath) {
private boolean probe(File modelFile) {
try (JsonParser parser = Jackson.mapper().createParser(modelFile)) {
while (parser.nextToken() != null) {
JsonToken token = parser.getCurrentToken();
JsonToken token = parser.currentToken();
if (token == JsonToken.FIELD_NAME) {
if ("tree_info".equals(parser.getCurrentName())) return true;
if ("tree_info".equals(parser.currentName())) return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

/**
* Parses predicate queries from JSON.
*
* Input JSON is assumed to have the following format:
* {
* "features": [
Expand Down Expand Up @@ -46,7 +45,7 @@ public void parseJsonQuery(
try (JsonParser parser = factory.createParser(json)) {
skipToken(parser, JsonToken.START_OBJECT);
while (parser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = parser.getCurrentName();
String fieldName = parser.currentName();
switch (fieldName) {
case "features":
parseFeatures(parser, JsonParser::getText, featureHandler);
Expand Down Expand Up @@ -82,7 +81,7 @@ private static <V> void parseFeature(
long subqueryBitmap = SubqueryBitmap.DEFAULT_VALUE; // Specifying subquery bitmap is optional.

while (parser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = parser.getCurrentName();
String fieldName = parser.currentName();
skipToken(parser, JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT);
switch (fieldName) {
case "k":
Expand All @@ -100,11 +99,11 @@ private static <V> void parseFeature(
}
if (key == null) {
throw new IllegalArgumentException(
String.format("Feature key is missing! (%s)", parser.getCurrentLocation()));
String.format("Feature key is missing! (%s)", parser.currentLocation()));
}
if (value == null) {
throw new IllegalArgumentException(
String.format("Feature value is missing! (%s)", parser.getCurrentLocation()));
String.format("Feature value is missing! (%s)", parser.currentLocation()));
}
featureHandler.accept(key, value, subqueryBitmap);
}
Expand All @@ -114,7 +113,7 @@ private static void skipToken(JsonParser parser, JsonToken... expected) throws I
if (Arrays.stream(expected).noneMatch(e -> e.equals(actual))) {
throw new IllegalArgumentException(
String.format("Expected a token in %s, got %s (%s).",
Arrays.toString(expected), actual, parser.getTokenLocation()));
Arrays.toString(expected), actual, parser.currentTokenLocation()));
}
}

Expand Down
Loading

0 comments on commit 2dc47f1

Please sign in to comment.