protobuf-java-format
protobuf-java-format copied to clipboard
JsonFormat throws an exception when it faces an empty json object
I have this json = {"changed_aspect": "media", "object": "tag", "object_id": "??", "time": 1450979289, "subscription_id": 0, "data": {}}
JsonFormatter throws an error when it faces data field:
1:127: Expected identifier. -}
com.googlecode.protobuf.format.JsonFormat$ParseException: 1:127: Expected identifier. -}
at com.googlecode.protobuf.format.JsonFormat$Tokenizer.parseException(JsonFormat.java:734)
at com.googlecode.protobuf.format.JsonFormat$Tokenizer.consumeIdentifier(JsonFormat.java:537)
at com.googlecode.protobuf.format.JsonFormat.handleMissingField(JsonFormat.java:887)
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.mergeField(JsonFormat.java:875)
I'm curious whether the fasterxml (Jackson) based formatter has the same issue… We should add unit tests for both for this.
You're going to have to include your protobuf too - I can't make a unit test that fails without your change.