Skip to content

Commit 3a5e3b0

Browse files
committed
Add another test failing for #561 on master
1 parent 8dbf0f7 commit 3a5e3b0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

protobuf/src/test/java/tools/jackson/dataformat/protobuf/ReadPackedRepeatedTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tools.jackson.dataformat.protobuf;
22

33
import java.io.StringReader;
4+
import java.util.Map;
45

56
import org.junit.jupiter.api.Test;
67

@@ -12,7 +13,7 @@
1213

1314
public 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
}

protobuf/src/test/java/tools/jackson/dataformat/protobuf/WriteAsMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class WriteAsMapTest extends ProtobufTestBase
1515
final static String PROTOC =
1616
"package tutorial;\n"
1717
+"message Person {\n"
18-
+" required string name = 1;\n"
18+
+" required string name = 1;\n"
1919
+" required int32 id = 2;\n"
2020
+" optional string email = 3;\n"
2121
+" enum PhoneType {\n"

0 commit comments

Comments
 (0)