bivas / protobuf-java-format

Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
BSD 3-Clause "New" or "Revised" License
153 stars 97 forks source link

Exception when consuming unknown field with value being empty list #40

Closed kskalski closed 7 years ago

kskalski commented 7 years ago

parsing something like { "unknown": [] }

fails with com.googlecode.protobuf.format.JsonFormat$ParseException: 1:32: Expected string. at com.googlecode.protobuf.format.JsonFormat$Tokenizer.parseException(JsonFormat.java:734) at com.googlecode.protobuf.format.JsonFormat$Tokenizer.consumeString(JsonFormat.java:683) at com.googlecode.protobuf.format.JsonFormat.handleMissingField(JsonFormat.java:909) at com.googlecode.protobuf.format.JsonFormat.handleMissingField(JsonFormat.java:895) at com.googlecode.protobuf.format.JsonFormat.mergeField(JsonFormat.java:853) at com.googlecode.protobuf.format.JsonFormat.mergeField(JsonFormat.java:875) at com.googlecode.protobuf.format.JsonFormat.merge(JsonFormat.java:790)

kskalski commented 7 years ago

Looks like last branch in handleMissingField (https://github.com/bivas/protobuf-java-format/blob/master/src/main/java/com/googlecode/protobuf/format/JsonFormat.java#L908) should check if tokenizer.currentToken() starts with ' or " instead of blindly calling consumeString

bivas commented 7 years ago

Can you please prepare a test and PR?

kskalski commented 7 years ago

https://github.com/bivas/protobuf-java-format/pull/41

bivas commented 7 years ago

Merged #41