Skip to content

Commit 53888b9

Browse files
committed
Add tests for #106 too
1 parent 8ef0350 commit 53888b9

File tree

6 files changed

+105
-6
lines changed

6 files changed

+105
-6
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/AmbiguousUnionWriteTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class AmbiguousUnionWriteTest extends AvroTestBase
2424
);
2525

2626
static class StringWrapper {
27-
public String value;
27+
public Object value;
2828

29-
public StringWrapper(String v) { value = v; }
29+
public StringWrapper(Object v) { value = v; }
3030
protected StringWrapper() { }
3131
}
3232

@@ -41,9 +41,12 @@ protected StringWrapper() { }
4141
public void testWriteNoAmbiguity() throws Exception
4242
{
4343
AvroSchema schema = MAPPER.schemaFrom(SCHEMA_WITH_AMBIGUITY);
44+
StringWrapper input = new StringWrapper("foobar");
45+
// 23-Aug-2017, tatu: we could trigger exception with this, however:
46+
// StringWrapper input = new StringWrapper(new java.util.HashMap<String,Integer>());
4447
byte[] b = MAPPER.writerFor(StringWrapper.class)
4548
.with(schema)
46-
.writeValueAsBytes(new StringWrapper("foobar"));
49+
.writeValueAsBytes(input);
4750
StringWrapper output = MAPPER.readerFor(StringWrapper.class)
4851
.with(schema)
4952
.readValue(b);

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java

-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ private JsonToken _skipUnknownField(int tag, int wireType) throws IOException
959959
// Note: may be null; if so, value needs to be skipped
960960
_currentField = _currentMessage.field(tag >> 3);
961961
if (_currentField == null) {
962-
_skipUnknownValue(wireType);
963962
continue;
964963
}
965964
_parsingContext.setCurrentName(_currentField.name);

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/ReadSimpleTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public NamedStrings(String n, String... v) {
4848
}
4949
}
5050

51-
final ObjectMapper MAPPER = new ObjectMapper(new ProtobufFactory());
52-
5351
/*
5452
/**********************************************************
5553
/* Test methods
5654
/**********************************************************
5755
*/
5856

57+
final ObjectMapper MAPPER = new ProtobufMapper();
58+
5959
public void testReadPointInt() throws Exception
6060
{
6161
ProtobufSchema schema = ProtobufSchemaLoader.std.parse(PROTOC_BOX, "Point");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.fasterxml.jackson.dataformat.protobuf;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import com.fasterxml.jackson.core.*;
6+
7+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
8+
9+
public class ReadUnkownFieldsTest extends ProtobufTestBase
10+
{
11+
static class OneField {
12+
13+
@JsonProperty(value = "f3", index = 3)
14+
private int f3;
15+
16+
public int getF3() {
17+
return f3;
18+
}
19+
20+
public void setF3(int f3) {
21+
this.f3 = f3;
22+
}
23+
}
24+
25+
static class ThreeField {
26+
27+
@JsonProperty(value = "f1", index = 1)
28+
private int f1;
29+
30+
@JsonProperty(value = "f2", index = 2)
31+
private int f2;
32+
33+
@JsonProperty(value = "f3", index = 3)
34+
private int f3;
35+
36+
public int getF1() {
37+
return f1;
38+
}
39+
40+
public void setF1(int f1) {
41+
this.f1 = f1;
42+
}
43+
44+
public int getF2() {
45+
return f2;
46+
}
47+
48+
public void setF2(int f2) {
49+
this.f2 = f2;
50+
}
51+
52+
public int getF3() {
53+
return f3;
54+
}
55+
56+
public void setF3(int f3) {
57+
this.f3 = f3;
58+
}
59+
}
60+
61+
/*
62+
/**********************************************************
63+
/* Test methods
64+
/**********************************************************
65+
*/
66+
67+
final ProtobufMapper MAPPER = new ProtobufMapper();
68+
69+
public void testMultipleUnknown() throws Exception
70+
{
71+
ProtobufMapper mapper = new ProtobufMapper();
72+
73+
ThreeField threeField = new ThreeField();
74+
threeField.setF1(1);
75+
threeField.setF2(2);
76+
threeField.setF3(3);
77+
78+
ProtobufSchema schemaWith3 = MAPPER.generateSchemaFor(ThreeField.class);
79+
byte[] in = mapper.writerFor(ThreeField.class).with(schemaWith3)
80+
.writeValueAsBytes(threeField);
81+
82+
ProtobufSchema schemaWith1 = MAPPER.generateSchemaFor(OneField.class);
83+
OneField oneField = mapper.readerFor(OneField.class).with(schemaWith1)
84+
// important: skip through unknown
85+
.with(JsonParser.Feature.IGNORE_UNDEFINED)
86+
.readValue(in);
87+
88+
assertEquals(threeField.getF3(), oneField.getF3());
89+
}
90+
}

release-notes/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ marsqing@github
2727
(2.8.9)
2828
* Reported #94: (protobuf) Should _ensureRoom in ProtobufGenerator.writeString()
2929
(2.8.10)
30+
* Reported #106, contributed fix for: calling _skipUnknownValue() twice
31+
(2.8.11 / 2.9.1)

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Modules:
1313

1414
#95: Add new method, `withUnsafeReaderSchema` in `AvroSchema` to allow avoiding verification exception
1515

16+
2.8.11 (not yet released)
17+
18+
#106: fix calling _skipUnknownValue() twice
19+
(reported, contributed fix for by marsqing@github@github)
20+
1621
2.8.10 (24-Aug-2017)
1722

1823
#94: Should _ensureRoom in ProtobufGenerator.writeString()

0 commit comments

Comments
 (0)