-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
If I have a protobuf message with unknown fields:
leaf1: "Hello"
leaf2: 23
leaf3: 41
4: "world"
where leaf1, leaf2, and leaf3 are my known fields, and 4 is an unknown field. I then convert to json like so:
return new JsonFormat().printToString(protobuf);I get the following:
{"leaf1": "Hello","leaf2": 23,"leaf3": [41], "4": ["world"]}`However, if I then deserialize the json back like so:
public static <T extends Message> T convertToProtobuf(String json, T defaultInstance)
throws ParseException {
Builder builder = defaultInstance.newBuilderForType();
JsonFormat format = new JsonFormat();
format.merge(json, ExtensionRegistry.getEmptyRegistry(), builder);
return (T)builder.build();
}then my result is the following:
leaf1: "Hello"
leaf2: 23
leaf3: 41
The problem is field 4 is not present in the reconstituted proto as an unknown field. Am I doing something wrong, or is this not supported? Thanks!
Metadata
Metadata
Assignees
Labels
No labels