Skip to content

Commit fe3563b

Browse files
author
Karl Rieb
committed
Fix deserialization bug when deserializing unrecognized struct fields.
1 parent 7ca71a3 commit fe3563b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.1.1
2+
---------------------------------------------
3+
- Fix "Required field ... missing" deserialization bug caused by certain backwards-compatible response changes from the server.
4+
15
2.1.0 (2016-07-29)
26
---------------------------------------------
37
- Update to latest API specs:

src/main/java/com/dropbox/core/stone/StoneSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ protected static void expectEndArray(JsonParser p) throws IOException, JsonParse
116116

117117
protected static void skipValue(JsonParser p) throws IOException, JsonParseException {
118118
if (p.getCurrentToken().isStructStart()) {
119-
p.skipChildren();
119+
p.skipChildren(); // will leave parser at end token (e.g. '}' or ']')
120+
p.nextToken();
120121
} else if (p.getCurrentToken().isScalarValue()) {
121122
p.nextToken();
122123
} else {

src/test/java/com/dropbox/core/stone/test/DataTypeSerializationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public void testUnknownStructFields() throws Exception {
6767
Dimensions actual = Dimensions.Serializer.INSTANCE.deserialize(json);
6868

6969
assertEquals(actual, expected);
70+
71+
// sometimes the order can matter. Add an unknown struct field early to see if we skip it properly
72+
json = "{\"height\":768,\"foo\":{\"bar\":[1, 2, 3],\"baz\":false},\"alpha\":0.5,\"width\":1024}";
73+
expected = new Dimensions(1024, 768);
74+
actual = Dimensions.Serializer.INSTANCE.deserialize(json);
75+
76+
assertEquals(actual, expected);
7077
}
7178

7279
@Test

0 commit comments

Comments
 (0)