I have a fairly simple android app, it gets protobuf data from a web server and has a java class generated by protoc.
Now I have no need for any other data than this data in my app. So i thought I would simply use this data rather than wrapping it since this would just be a lot of extra work.
However sometimes i expand the tree with new data (nested messages in proto file) and then i need to be able to insert these in the current tree which is not allowed since the java class always returns unmodifiableList.
I am now thinking that i could get the list with reflection, thus modifiable. It does not seem like a great solution but it beats doing extra work for wrapping the class and all the stuff therein. So my actual question is, is this a big no no or would it be okay.
I read somewhere that even within google they argue if it’s smart having the protobuf objects as data structure or only as pure send/recieve messages.
Protocol Buffer messages instances are immutable by design.
If you want to manipulate data originally from a protobuf, create a new Builder, using mergeFrom to prepopulate the original fields: