On Tue, Dec 16, 2008 at 2:27 AM, <atulatri2...@gmail.com> wrote:

> Hi,
> I have couple of questions regarding protocol buffers in java
> 1. I am using old bean style data structures. How can i migrate to
> protocol buffers and what problems may arise due to this migration.

This is a pretty broad question with many reasonable answers.  You could
keep your existing structures and just add methods to convert between them
and protocol buffers (see below).  This would be easy but would be annoying
to maintain since every time you added a field you'd have to update the bean
class.  Alternatively, you could completely replace your bean-style classes
with protocol message classes, but this will require refactoring your code
to work with immutable objects.  Most code tends to be pretty easy to
refactor (because most code will tend to construct data objects all at once
and then not modify them afterwards, which is what protocol buffer objects
require), but some code may be more complicated to rework.  Also, if you
have a lot of code it could be painful.  A third option is to replace your
bean objects with protocol message builders and use those everywhere, since
they have both setters and getters and thus can operate like mutable
objects.  However, this is kind of ugly and not the way builders are meant
to be used.

I would probably recommend the first option, as it keeps your code more
independent of protocol buffers, so you can more easily change your mind
later if you want to.

> 2. How can i serialize bean style data structures using protocol
> buffers?

You'd need to add methods which convert between your bean class and protocol
message objects.  For example:

  public MyMessageType toProto() {
    return MyMessageType.newBuilder()

  public void fromProto(MyMessageType proto) {

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to