How to convert from Json to Protobuf?

后端 未结 2 1660
误落风尘
误落风尘 2020-12-13 18:14

I\'m new to using protobuf, and was wondering if there is a simple way to convert a json stream/string to a protobuf stream/string in Java?

For example,



        
2条回答
  •  情话喂你
    2020-12-13 18:48

    With proto3 you can do this using JsonFormat. It parses directly from the JSON representation, so there is no need for separately calling MyMessage.parseFrom(...). Something like this should work:

    JsonFormat.parser().merge(json_string, builder);
    

提交回复
热议问题