I'm trying to long-term serialize a bunch of objects related by a strong class hierarchy in java, and I'd like to use protocol buffers to do it due to their simplicity, performance, and ease of upgrade. However, they don't provide much support for polymorphism. Right now, the way I'm handling it is by having a "one message to rule them all" solution that has a required string uri field that allows me to instantiate the correct type via reflection, then a bunch of optional fields for all the other possible classes I could serialize, only one of which will be used (based on the value of the uri field). Is there a better way to handle polymorphism, or is this as good as I'm going to get?
标签:
protocol-buffers
相关问题
- creating callbacks and structs for repeated field
- How to deal with unknown protobuf fields in Java?
- Is it possible to use Apache Thrift without RPC?
- How do I Import a .proto file from a dependency ja
- compile protocol buffers 3 timestamp type in c# vi
相关文章
- How to not freeze the UI, and wait for response?
- Protocol message tag had invalid wire type
- Protobuf InvalidProtocolBufferException with some
- use protobuf3 with some lib which depends on proto
- How to serialize/deserialize a protobuf message th
- Parsing a raw Protocol Buffer byte stream in C#
- How can i write my own RPC Implementation for Prot
- Read value of enum extension in protocol buffer
A solution a little better, for me, that the @Łukasz Marciniak's answer.
If Bar extends Foo, simply write:
So if Foo evolves only Foo message is modified.