gRPC - Response Construction

41 views
Skip to first unread message

viji....@gmail.com

unread,
Jul 4, 2020, 8:11:02 AM7/4/20
to grpc.io

Recently started using gRPC -Protobuf so the question might be asked earlier as well. Sorry if im repeating it here.

I have to convert one protobuf object to another protobuf object in Java.

Basically response construction. In normal Java world, we can have copy constructor or BeanUtils copy properties to copy the nested set of objects to destination. Similar to that Do i have any way to convert one builder object of a protobuf to another builder object generated from protobuf file.

sanjay...@google.com

unread,
Jul 5, 2020, 10:27:58 PM7/5/20
to grpc.io
Copy constructor implies copying object to the same type. You can use toBuilder() on the first object to get a builder that enables you to build the second object with the same values.

But when you say "convert one builder object ... to another builder object" do you mean a different type? That ordinarily is not possible.

Message has been deleted

viji....@gmail.com

unread,
Jul 6, 2020, 2:19:18 AM7/6/20
to grpc.io
But when you say "convert one builder object ... to another builder object" do you mean a different type? That ordinarily is not possible.

Yes Different Type. Now we are reading each property from source and setting it in destination and building destination Object.

Sanjay Pujare

unread,
Jul 6, 2020, 2:37:19 AM7/6/20
to viji....@gmail.com, grpc.io
You can get all the fields of a protobuf object using getAllFields() (for the source object) and then use setField() on each field on the destination object builder.

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/ESjCIz_2grc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/c04abc12-90e7-4732-b15e-a43a5f87a663o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages