8
8
import com .fasterxml .jackson .annotation .JsonProperty ;
9
9
import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
10
10
import com .fasterxml .jackson .core .JsonParser ;
11
+ import com .fasterxml .jackson .core .JsonToken ;
12
+ import com .fasterxml .jackson .databind .ObjectReader ;
11
13
import com .fasterxml .jackson .dataformat .protobuf .schema .ProtobufSchema ;
12
14
13
15
import static org .junit .jupiter .api .Assertions .assertEquals ;
16
+ import static org .junit .jupiter .api .Assertions .assertNull ;
14
17
15
18
public class ReadNestedUnknownFieldsTest extends ProtobufTestBase
16
19
{
@@ -128,7 +131,7 @@ public static class Embed {
128
131
129
132
private final ProtobufMapper MAPPER = new ProtobufMapper ();
130
133
131
- // [dataformats-binary#108]
134
+ // [dataformats-binary#108], [dataformats-binary#584]
132
135
@ Test
133
136
public void testMultipleUnknown () throws Exception
134
137
{
@@ -138,15 +141,36 @@ public void testMultipleUnknown() throws Exception
138
141
nestedTwoField .setNested2 (2 );
139
142
moreNestedField .setF1 (nestedTwoField );
140
143
141
- byte [] in = MAPPER .writerFor (MoreNestedField .class )
144
+ byte [] doc = MAPPER .writerFor (MoreNestedField .class )
142
145
.with (MAPPER .generateSchemaFor (MoreNestedField .class ))
143
146
.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
+ }
144
167
168
+ // and only then test databinding
145
169
LessNestedField lesser = MAPPER .readerFor (LessNestedField .class )
146
170
.with (MAPPER .generateSchemaFor (LessNestedField .class ))
147
171
// important: skip through unknown
148
172
.with (JsonParser .Feature .IGNORE_UNDEFINED )
149
- .readValue (in );
173
+ .readValue (doc );
150
174
151
175
assertEquals (moreNestedField .getF1 ().getNested2 (), lesser .getF1 ().getNested2 ());
152
176
}
0 commit comments