what's the right way to do polymorphism with protocol buffers?
Posted
by user364003
on Stack Overflow
See other posts from Stack Overflow
or by user364003
Published on 2010-06-10T21:38:30Z
Indexed on
2010/06/10
21:43 UTC
Read the original article
Hit count: 154
protocol-buffers
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?
© Stack Overflow or respective owner