8
8
import com .fasterxml .jackson .annotation .JsonProperty ;
9
9
import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
10
10
11
- import tools .jackson .core .StreamReadFeature ;
12
-
11
+ import tools .jackson .core .*;
12
+ import tools .jackson .databind .MapperFeature ;
13
+ import tools .jackson .databind .ObjectReader ;
13
14
import tools .jackson .dataformat .protobuf .schema .ProtobufSchema ;
14
15
15
- import static org .junit .jupiter .api .Assertions .assertEquals ;
16
+ import static org .junit .jupiter .api .Assertions .* ;
16
17
17
18
public class ReadNestedUnknownFieldsTest extends ProtobufTestBase
18
19
{
@@ -128,7 +129,14 @@ public static class Embed {
128
129
/**********************************************************
129
130
*/
130
131
131
- private final ProtobufMapper MAPPER = newObjectMapper ();
132
+ // 30-Apr-2025, tatu: Looks like we have a bug of some kind, exposed
133
+ // by change to `MapperFeature.DEFAULT_VIEW_INCLUSION` defaults
134
+ // (changed to `false`) but probably not caused by the change
135
+
136
+ // private final ProtobufMapper MAPPER = newObjectMapper();
137
+ private final ProtobufMapper MAPPER = newMapperBuilder ()
138
+ .enable (MapperFeature .DEFAULT_VIEW_INCLUSION )
139
+ .build ();
132
140
133
141
// [dataformats-binary#108]
134
142
@ Test
@@ -140,15 +148,39 @@ public void testMultipleUnknown() throws Exception
140
148
nestedTwoField .setNested2 (2 );
141
149
moreNestedField .setF1 (nestedTwoField );
142
150
143
- byte [] in = MAPPER .writerFor (MoreNestedField .class )
151
+ byte [] doc = MAPPER .writerFor (MoreNestedField .class )
144
152
.with (MAPPER .generateSchemaFor (MoreNestedField .class ))
145
153
.writeValueAsBytes (moreNestedField );
146
-
147
- LessNestedField lesser = MAPPER .readerFor (LessNestedField .class )
148
- .with (MAPPER . generateSchemaFor ( LessNestedField . class ) )
154
+ final ProtobufSchema schema = MAPPER . generateSchemaFor ( LessNestedField . class );
155
+ final ObjectReader protoR = MAPPER .readerFor (LessNestedField .class )
156
+ .with (schema )
149
157
// important: skip through unknown
150
- .with (StreamReadFeature .IGNORE_UNDEFINED )
151
- .readValue (in );
158
+ .with (StreamReadFeature .IGNORE_UNDEFINED );
159
+
160
+ //System.err.println("-> "+MAPPER.valueToTree(protoR.readValue(doc)).toPrettyString());
161
+
162
+ // 30-Apr-2025, tatu: First, iterate over tokens
163
+ // ... alas, does not actually
164
+ /*
165
+ try (JsonParser p = protoR.createParser(doc)) {
166
+ assertToken(JsonToken.START_OBJECT, p.nextToken());
167
+ assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
168
+ assertEquals("f1", p.currentName());
169
+ assertToken(JsonToken.START_OBJECT, p.nextToken());
170
+ assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
171
+ assertEquals("nested2", p.currentName());
172
+ assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
173
+ assertEquals(2, p.getIntValue());
174
+
175
+ assertToken(JsonToken.END_OBJECT, p.nextToken());
176
+ assertToken(JsonToken.END_OBJECT, p.nextToken());
177
+ assertNull(p.nextToken());
178
+ }
179
+ */
180
+
181
+ // and only then use databinding
182
+
183
+ LessNestedField lesser = protoR .readValue (doc );
152
184
153
185
assertEquals (moreNestedField .getF1 ().getNested2 (), lesser .getF1 ().getNested2 ());
154
186
}
0 commit comments