1
1
package tools .jackson .dataformat .protobuf ;
2
2
3
3
import java .io .StringReader ;
4
+ import java .util .Map ;
4
5
5
6
import org .junit .jupiter .api .Test ;
6
7
12
13
13
14
public class ReadPackedRepeatedTest extends ProtobufTestBase
14
15
{
15
- final ProtobufMapper MAPPER = new ProtobufMapper ();
16
+ private final ProtobufMapper MAPPER = newObjectMapper ();
16
17
17
18
@ Test
18
19
public void testPacked () throws Exception
@@ -31,4 +32,26 @@ public void testPacked() throws Exception
31
32
assertEquals (100 , t .get ("f" ).get (0 ).asInt ());
32
33
assertEquals (200 , t .get ("f" ).get (1 ).asInt ());
33
34
}
35
+
36
+ // 31-Jan-2025, tatu: [dataformats-binary#561] Problem with sparse arrays
37
+ // and trailing END_OBJECT
38
+ @ Test
39
+ public void testSparse561 () throws Exception
40
+ {
41
+ final String SCHEMA_STR =
42
+ "package mypackage;\n "
43
+ + "message t {\n "
44
+ + " repeated uint32 f = 1;\n "
45
+ + "}" ;
46
+
47
+ Map <String , Object > input = Map .of ("f" , new int [] { 1 , 2 });
48
+
49
+ ProtobufSchema schema = MAPPER .schemaLoader ().load (new StringReader (SCHEMA_STR ));
50
+ byte [] encoded = MAPPER .writer (schema ).writeValueAsBytes (input );
51
+ JsonNode t = MAPPER .readerFor (JsonNode .class ).with (schema ).readValue (encoded );
52
+
53
+ assertEquals (2 , t .get ("f" ).size ());
54
+ assertEquals (1 , t .get ("f" ).get (0 ).asInt ());
55
+ assertEquals (2 , t .get ("f" ).get (1 ).asInt ());
56
+ }
34
57
}
0 commit comments