Skip to content

Commit 8562933

Browse files
committed
Backport fix for #76
1 parent c1ebb55 commit 8562933

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schema/ProtobufField.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public final boolean isArray() {
191191
}
192192

193193
public final boolean isValidFor(int typeTag) {
194-
return (typeTag == type.getWireType());
194+
return (typeTag == type.getWireType()
195+
// 13-Apr-2017, tatu: to fix [dataformats-binary#76]
196+
|| packed && repeated && typeTag == WireType.LENGTH_PREFIXED);
195197
}
196198

197199
@Override
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fasterxml.jackson.dataformat.protobuf;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
5+
6+
import java.io.StringReader;
7+
8+
public class ReadPackedRepeatedTest extends ProtobufTestBase
9+
{
10+
final ProtobufMapper MAPPER = new ProtobufMapper();
11+
12+
public void testPacked() throws Exception
13+
{
14+
final String SCHEMA_STR =
15+
"package mypackage;\n"
16+
+ "message t {\n"
17+
+ " repeated uint32 f = 1 [packed=true];\n"
18+
+ "}";
19+
final byte[] pb = {0xa, 0x3, 0x64, (byte)0xc8, 0x1}; // f = [100, 200]
20+
21+
ProtobufSchema schema = MAPPER.schemaLoader().load(new StringReader(SCHEMA_STR));
22+
JsonNode t = MAPPER.readerFor(JsonNode.class).with(schema).readValue(pb);
23+
24+
assertEquals(2, t.get("f").size());
25+
assertEquals(100, t.get("f").get(0).asInt());
26+
assertEquals(200, t.get("f").get(1).asInt());
27+
}
28+
}

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Michael Zeng (shotbythought@github)
1515

1616
* Reported #58 (avro): Regression due to changed namespace of inner enum types
1717
(2.8.8)
18+
19+
Kenji Noguchi (knoguchi@github)
20+
21+
* Reported #70 (protobuf), contributed fix: Can't deserialize packed repeated field
22+
(2.8.9)

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Modules:
1818
(reported by Peter R)
1919
#62: (cbor) `java.lang.ArrayIndexOutOfBoundsException` at `CBORGenerator.java`:548
2020
#67: (proto) Serialization of multiple nesting levels has issues
21+
#70: (proto) Can't deserialize packed repeated field
22+
(reported by Kenji N)
2123

2224
2.8.7 (21-Feb-2017)
2325

0 commit comments

Comments
 (0)