anydoby / protobuf-java-format

Automatically exported from code.google.com/p/protobuf-java-format
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

JSON formatting breaks when a proto Message contains UnknownFields #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Message with UnknownFields
2. Call `JsonFormat.printToString` to convert message to JSON

Sample Code
-----------

User.Builder userB = User.newBuilder().setFirstName("Rajini").setLastName("Kanth"); // Used setUnknownFields just to reproduce the issue. userB.setUnknownFields(UnknownFieldSet.newBuilder().addField(50, Field.newBuilder().addFixed32(999).build()).build());

System.out.println(JsonFormat.printToString(userB.build()));


What is the expected output? What do you see instead?

Expected: 
{"first_name": "Rajini","last_name": "Kanth", "50": 0x000003e7}

Actual: 
{"first_name": "Rajini","last_name": "Kanth""50": 0x000003e7
}
// Comma is missing after `last_name` field

What version of the product are you using? On what operating system?

protobuf-format-java-1.1.jar

Please provide any additional information below.

I used `setUnknownFields` just to reproduce the issue. In our case, Same proto 
object will be present in Server and Client server. When we add a new field in 
Server, client will consider new field as unknown field till client upgrade to 
latest protobuf object.

Jsonformat.printString formatting breaks when server and client has different 
version of protobuf object and server has some additional field.

Original issue reported on code.google.com by mani...@gmail.com on 18 Jun 2015 at 12:35