88import com .fasterxml .jackson .annotation .JsonProperty ;
99import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
1010import com .fasterxml .jackson .core .JsonParser ;
11+ import com .fasterxml .jackson .core .JsonToken ;
12+ import com .fasterxml .jackson .databind .ObjectReader ;
1113import com .fasterxml .jackson .dataformat .protobuf .schema .ProtobufSchema ;
1214
1315import static org .junit .jupiter .api .Assertions .assertEquals ;
16+ import static org .junit .jupiter .api .Assertions .assertNull ;
1417
1518public 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 }
0 commit comments