Skip to content

Commit 7867272

Browse files
authored
Fix #561: avoid returning extra END_OBJECT at end root-level array value (#562)
1 parent 3a5e3b0 commit 7867272

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

protobuf/src/main/java/tools/jackson/dataformat/protobuf/ProtobufParser.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,22 @@ protected void _releaseBuffers()
492492
@Override
493493
public JsonToken nextToken() throws JacksonException
494494
{
495+
System.out.println("nextToken(): state="+_state+", ptr="+_inputPtr);
495496
JsonToken t = nextTokenX();
496497
if (t == JsonToken.PROPERTY_NAME) {
497-
System.out.print("Field name: "+currentName());
498+
System.out.print(" Field name: "+currentName());
498499
} else if (t == JsonToken.VALUE_NUMBER_INT) {
499-
System.out.print("Int: "+getIntValue());
500+
System.out.print(" Int: "+getIntValue());
500501
} else if (t == JsonToken.VALUE_STRING) {
501-
System.out.print("String: '"+getText()+"'");
502+
System.out.print(" String: '"+getString()+"'");
502503
} else {
503-
System.out.print("Next: "+t);
504+
System.out.print(" Next: "+t);
504505
}
505506
System.out.println(" (state now: "+_state+", ptr "+_inputPtr+")");
506507
return t;
507508
}
508509
509-
public JsonToken nextTokenX() throws JacksonException {
510+
public JsonToken nextTokenX() throws JacksonException
510511
*/
511512

512513
@Override
@@ -1041,6 +1042,7 @@ public String nextName() throws JacksonException
10411042
return name;
10421043
}
10431044
if (_state == STATE_MESSAGE_END) {
1045+
close(); // sets state to STATE_CLOSED
10441046
_updateToken(JsonToken.END_OBJECT);
10451047
return null;
10461048
}
@@ -1126,6 +1128,7 @@ public boolean nextName(SerializableString sstr) throws JacksonException
11261128
return name.equals(sstr.getValue());
11271129
}
11281130
if (_state == STATE_MESSAGE_END) {
1131+
close(); // sets state to STATE_CLOSED
11291132
_updateToken(JsonToken.END_OBJECT);
11301133
return false;
11311134
}
@@ -1215,6 +1218,7 @@ public int nextNameMatch(PropertyNameMatcher matcher) throws JacksonException
12151218
return matcher.matchName(name);
12161219
}
12171220
if (_state == STATE_MESSAGE_END) {
1221+
close(); // sets state to STATE_CLOSED
12181222
_updateToken(JsonToken.END_OBJECT);
12191223
return PropertyNameMatcher.MATCH_END_OBJECT;
12201224
}
@@ -1236,7 +1240,7 @@ private int _nextNameMatch2(PropertyNameMatcher matcher) throws JacksonException
12361240

12371241
/*
12381242
/**********************************************************************
1239-
/* Public API, traversal, optimized: nextFieldName()
1243+
/* Public API, traversal, optimized: nextName()
12401244
/**********************************************************************
12411245
*/
12421246

protobuf/src/test/java/tools/jackson/dataformat/protobuf/ReadPackedRepeatedTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public void testSparse561() throws Exception
4444
+ " repeated uint32 f = 1;\n"
4545
+ "}";
4646

47-
Map<String, Object> input = Map.of("f", new int[] { 1, 2 });
47+
Map<String, Object> input = Map.of("f", new int[] { 100, 200 });
4848

4949
ProtobufSchema schema = MAPPER.schemaLoader().load(new StringReader(SCHEMA_STR));
5050
byte[] encoded = MAPPER.writer(schema).writeValueAsBytes(input);
5151
JsonNode t = MAPPER.readerFor(JsonNode.class).with(schema).readValue(encoded);
5252

5353
assertEquals(2, t.get("f").size());
54-
assertEquals(1, t.get("f").get(0).asInt());
55-
assertEquals(2, t.get("f").get(1).asInt());
54+
assertEquals(100, t.get("f").get(0).asInt());
55+
assertEquals(200, t.get("f").get(1).asInt());
5656
}
5757
}

0 commit comments

Comments
 (0)