Skip to content

Commit f1ddf07

Browse files
committed
Fix #135
1 parent ba93ae2 commit f1ddf07

File tree

6 files changed

+81
-15
lines changed

6 files changed

+81
-15
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/annotations/StringableTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import lombok.Data;
1515
import org.apache.avro.reflect.AvroSchema;
1616
import org.apache.avro.reflect.Stringable;
17-
import org.apache.avro.specific.SpecificData;
1817
import org.junit.Test;
1918

2019
import com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil;
@@ -26,8 +25,8 @@
2625
/**
2726
* Tests support for using classes marked {@link Stringable @Stringable} as map keys. These classes must have a constructor which accepts a
2827
* single string as an argument, and their {@link #toString()} must return a serialized version of the object that can be passed back into
29-
* the constructor to recreate it. In addition, Avro considers the following classes {@link SpecificData#stringableClasses} stringable by
30-
* default}:
28+
* the constructor to recreate it. In addition, Avro considers the following classes
29+
* stringable (see {code SpecificData.stringableClasses()}) by default:
3130
* <ul>
3231
* <li>{@link File}</li>
3332
* <li>{@link BigInteger}</li>

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,9 @@ public JsonToken nextToken() throws IOException
660660
}
661661

662662
case STATE_MESSAGE_END: // occurs if we end with array
663+
close(); // sets state to STATE_CLOSED
663664
return (_currToken = JsonToken.END_OBJECT);
664-
665+
665666
case STATE_CLOSED:
666667
return null;
667668

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

+65-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.io.IOException;
44

5-
import org.junit.Assert;
6-
import org.junit.Test;
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
7+
import com.fasterxml.jackson.core.JsonParser;
8+
import com.fasterxml.jackson.core.JsonToken;
79

810
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
911
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
@@ -95,11 +97,25 @@ public void setA(String a) {
9597
}
9698
}
9799

98-
@Test
100+
// [dataformats-binary#135]: endless END_OBJECT at end of doc
101+
@JsonPropertyOrder({ "name", "age", "emails", "boss" })
102+
static class Employee135 {
103+
public int age;
104+
105+
public String[] emails;
106+
}
107+
108+
/*
109+
/**********************************************************
110+
/* Test methods
111+
/**********************************************************
112+
*/
113+
114+
private final ProtobufMapper MAPPER = new ProtobufMapper();
115+
99116
public void testNestedRoundtrip() throws IOException
100117
{
101118
TestObject testClass = new TestObject();
102-
ProtobufMapper om = new ProtobufMapper();
103119
ProtobufSchema s = ProtobufSchemaLoader.std.parse(PROTO);
104120
testClass.a = VALUE_A;
105121
testClass.b = new TestSub();
@@ -109,14 +125,53 @@ public void testNestedRoundtrip() throws IOException
109125
testClass.b.d = new TestSubSub();
110126
testClass.b.d.a = VALUE_SUB_A;
111127

112-
byte[] proto = om.writer(s)
128+
byte[] proto = MAPPER.writer(s)
113129
.writeValueAsBytes(testClass);
114-
TestObject res = om.readerFor(TestObject.class).with(s)
130+
TestObject res = MAPPER.readerFor(TestObject.class).with(s)
115131
.readValue(proto);
116132

117-
Assert.assertEquals(VALUE_A, res.a);
118-
Assert.assertEquals(VALUE_C, res.b.c);
119-
Assert.assertEquals(VALUE_B, res.b.b);
120-
Assert.assertEquals(VALUE_SUB_A, res.b.d.a);
133+
assertEquals(VALUE_A, res.a);
134+
assertEquals(VALUE_C, res.b.c);
135+
assertEquals(VALUE_B, res.b.b);
136+
assertEquals(VALUE_SUB_A, res.b.d.a);
137+
}
138+
139+
// [dataformats-binary#135]: endless END_OBJECT at end of doc
140+
public void testIssue135() throws Exception
141+
{
142+
String protobuf_str = "message Employee {\n"
143+
+ " required int32 age = 1;\n"
144+
+ " repeated string emails = 3;\n"
145+
+ "}\n";
146+
final ProtobufSchema schema = MAPPER.schemaLoader().parse(protobuf_str);
147+
148+
Employee135 empl = new Employee135();
149+
empl.age = 30;
150+
empl.emails = new String[]{"[email protected]"};
151+
152+
byte[] protobufData = MAPPER.writer(schema)
153+
.writeValueAsBytes(empl);
154+
155+
JsonParser p = new ProtobufFactory().createParser(protobufData);
156+
p.setSchema(schema);
157+
158+
assertToken(JsonToken.START_OBJECT, p.nextToken());
159+
160+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
161+
assertEquals("age", p.currentName());
162+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
163+
assertEquals(30, p.getIntValue());
164+
165+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
166+
assertEquals("emails", p.currentName());
167+
assertToken(JsonToken.START_ARRAY, p.nextToken());
168+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
169+
assertEquals("[email protected]", p.getText());
170+
assertToken(JsonToken.END_ARRAY, p.nextToken());
171+
172+
assertToken(JsonToken.END_OBJECT, p.nextToken());
173+
174+
assertNull(p.nextToken());
175+
p.close();
121176
}
122177
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Binary(int id, byte[] data, int trailer) {
2626
this.trailer = trailer;
2727
}
2828
}
29-
29+
3030
/*
3131
/**********************************************************
3232
/* Test methods

release-notes/CREDITS

+6
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,11 @@ philipa@github
6060
(2.9.3)
6161

6262
Jacek Lach (JacekLach@github)
63+
6364
* Reported #124: Invalid value returned for negative int32 where the absolute value is > 2^31 - 1
6465
(2.9.3)
66+
67+
Leo Wang (wanglingsong@github)
68+
69+
* Reported #135: Infinite sequence of `END_OBJECT` tokens returned at end of streaming read
70+
(2.9.6)

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Modules:
99
=== Releases ===
1010
------------------------------------------------------------------------
1111

12+
2.9.6 (not yet released)
13+
14+
#135: Infinite sequence of `END_OBJECT` tokens returned at end of streaming read
15+
(reported by Leo W)
16+
1217
2.9.5 (26-Feb-2018)
1318

1419
#128 (protobuf) Fix skip unknown WireType.FIXED_64BIT value bug

0 commit comments

Comments
 (0)