Skip to content

Commit

Permalink
AVRO-1711: Java: Fix JsonDecoder#skipChildren skipping extra tokens.
Browse files Browse the repository at this point in the history
Contributed by Zoltan Farkas and Thiruvalluvan M. G.
  • Loading branch information
rdblue committed May 8, 2016
1 parent 4fe9b45 commit 7e10bab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Trunk (not yet released)

AVRO-1814: Generated java code fails on variables with a TLD name like 'org' (nielsbasjes)

AVRO-1711: Java: Fix JsonParser#skipChildren to implement its defined contract.
(Zoltan Farkas and Thiruvalluvan M. G. via blue)

Avro 1.8.0 (22 January 2016)

INCOMPATIBLE CHANGES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@ public JsonToken nextToken() throws IOException {

@Override
public JsonParser skipChildren() throws IOException {
int level = 0;
do {
switch(elements.get(pos++).token) {
JsonToken tkn = elements.get(pos).token;
int level = (tkn == JsonToken.START_ARRAY || tkn == JsonToken.END_ARRAY) ? 1 : 0;
while (level > 0) {
switch(elements.get(++pos).token) {
case START_ARRAY:
case START_OBJECT:
level++;
Expand All @@ -591,7 +592,7 @@ public JsonParser skipChildren() throws IOException {
level--;
break;
}
} while (level > 0);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,21 @@ private void checkNumeric(String type, Object value) throws Exception {
}
}

// Ensure that even if the order of fields in JSON is different from the order in schema,
// it works.
@Test public void testReorderFields() throws Exception {
String w =
"{\"type\":\"record\",\"name\":\"R\",\"fields\":"
+"[{\"type\":\"long\",\"name\":\"l\"},"
+"{\"type\":{\"type\":\"array\",\"items\":\"int\"},\"name\":\"a\"}"
+"]}";
Schema ws = Schema.parse(w);
DecoderFactory df = DecoderFactory.get();
String data = "{\"a\":[1,2],\"l\":100}{\"l\": 200, \"a\":[1,2]}";
JsonDecoder in = df.jsonDecoder(ws, data);
Assert.assertEquals(100, in.readLong());
in.skipArray();
Assert.assertEquals(200, in.readLong());
in.skipArray();
}
}

0 comments on commit 7e10bab

Please sign in to comment.