Skip to content

Commit fc30d4d

Browse files
committed
Merge branch '2.19' into 2.x
2 parents 29c171a + 10ff02c commit fc30d4d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,12 @@ private JsonToken _skipUnknownField(int tag, int wireType) throws IOException
967967
continue;
968968
}
969969
_parsingContext.setCurrentName(_currentField.name);
970-
_state = STATE_ROOT_VALUE;
970+
// 30-Apr-2025, tatu: [dataformats-binary#584] may be called for root and nested
971+
if (_state == STATE_NESTED_KEY) {
972+
_state = STATE_NESTED_VALUE;
973+
} else {
974+
_state = STATE_ROOT_VALUE;
975+
}
971976
// otherwise quickly validate compatibility
972977
if (!_currentField.isValidFor(wireType)) {
973978
_reportIncompatibleType(_currentField, wireType);

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/ReadNestedUnknownFieldsTest.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import com.fasterxml.jackson.annotation.JsonProperty;
99
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
1010
import com.fasterxml.jackson.core.JsonParser;
11+
import com.fasterxml.jackson.core.JsonToken;
12+
import com.fasterxml.jackson.databind.ObjectReader;
1113
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
1214

1315
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertNull;
1417

1518
public class ReadNestedUnknownFieldsTest extends ProtobufTestBase
1619
{
@@ -128,7 +131,7 @@ public static class Embed {
128131

129132
private final ProtobufMapper MAPPER = new ProtobufMapper();
130133

131-
// [dataformats-binary#108]
134+
// [dataformats-binary#108], [dataformats-binary#584]
132135
@Test
133136
public void testMultipleUnknown() throws Exception
134137
{
@@ -138,15 +141,36 @@ public void testMultipleUnknown() throws Exception
138141
nestedTwoField.setNested2(2);
139142
moreNestedField.setF1(nestedTwoField);
140143

141-
byte[] in = MAPPER.writerFor(MoreNestedField.class)
144+
byte[] doc = MAPPER.writerFor(MoreNestedField.class)
142145
.with(MAPPER.generateSchemaFor(MoreNestedField.class))
143146
.writeValueAsBytes(moreNestedField);
147+
final ProtobufSchema schema = MAPPER.generateSchemaFor(LessNestedField.class);
148+
final ObjectReader protoR = MAPPER.readerFor(LessNestedField.class)
149+
.with(schema)
150+
// important: skip through unknown
151+
.with(JsonParser.Feature.IGNORE_UNDEFINED);
152+
153+
// 30-Apr-2025, tatu: [dataformats-binary#584]: First, iterate over tokens
154+
try (JsonParser p = protoR.createParser(doc)) {
155+
assertToken(JsonToken.START_OBJECT, p.nextToken());
156+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
157+
assertEquals("f1", p.currentName());
158+
assertToken(JsonToken.START_OBJECT, p.nextToken());
159+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
160+
assertEquals("nested2", p.currentName());
161+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
162+
assertEquals(2, p.getIntValue());
163+
assertToken(JsonToken.END_OBJECT, p.nextToken());
164+
assertToken(JsonToken.END_OBJECT, p.nextToken());
165+
assertNull(p.nextToken());
166+
}
144167

168+
// and only then test databinding
145169
LessNestedField lesser = MAPPER.readerFor(LessNestedField.class)
146170
.with(MAPPER.generateSchemaFor(LessNestedField.class))
147171
// important: skip through unknown
148172
.with(JsonParser.Feature.IGNORE_UNDEFINED)
149-
.readValue(in);
173+
.readValue(doc);
150174

151175
assertEquals(moreNestedField.getF1().getNested2(), lesser.getF1().getNested2());
152176
}

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Active maintainers:
5151
#569: (ion) `IonParser` fails to parse some `long` values saying
5252
they are out of range when they are not
5353
(reported, fix suggested by @seadbrane)
54+
#584: (protobuf) Missing `JsonToken.END_OBJECT` for nested Protobuf Objects
5455
- (ion) Upgrade `ion-java` to 1.11.10 (from 1.11.9)
5556

5657
2.18.3 (28-Feb-2025)

0 commit comments

Comments
 (0)