Java: JSON -> Protobuf & back conversion

后端 未结 9 2043
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 10:59

I have an existing system, which is using protobuf-based communication protocol between GUI and server. Now I would like to add some persistence, but at the moment

9条回答
  •  失恋的感觉
    2020-12-02 11:46

    As mentioned in an answer to a similar question, since v3.1.0 this is a supported feature of ProtocolBuffers. For Java, include the extension module com.google.protobuf:protobuf-java-util and use JsonFormat like so:

    JsonFormat.parser().ignoringUnknownFields().merge(json, yourObjectBuilder);
    YourObject value = yourObjectBuilder.build();
    

提交回复
热议问题