11package  tools .jackson .dataformat .protobuf ;
22
33import  java .io .StringReader ;
4+ import  java .util .Map ;
45
56import  org .junit .jupiter .api .Test ;
67
1213
1314public  class  ReadPackedRepeatedTest  extends  ProtobufTestBase 
1415{
15-     final  ProtobufMapper  MAPPER  = new   ProtobufMapper ();
16+     private   final  ProtobufMapper  MAPPER  = newObjectMapper ();
1617
1718    @ Test 
1819    public  void  testPacked () throws  Exception 
@@ -31,4 +32,26 @@ public void testPacked() throws Exception
3132        assertEquals (100 , t .get ("f" ).get (0 ).asInt ());
3233        assertEquals (200 , t .get ("f" ).get (1 ).asInt ());
3334    }
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+     }
3457}
0 commit comments