JAVA: Converting Struct protobuf type to Map<String, Object> in java

1,139 views
Skip to first unread message

Kush Trivedi

unread,
Jul 30, 2021, 2:07:16 PM7/30/21
to grpc.io
Hi,

I have been working on a java-grpc side-project & I have been stuck at a point. I have an variable of Struct(protobuf) type & now I want it to convert to Map<String, Object> since Jackson is unable to serialise a Struct(protobuf) type object.

I tried to search the web but it was all in vain, can anyone help how can I approach solving this problem?

Regards,
Kush

Eric Anderson

unread,
Aug 2, 2021, 2:03:44 PM8/2/21
to Kush Trivedi, grpc.io
On Fri, Jul 30, 2021 at 11:07 AM Kush Trivedi <kusht...@gmail.com> wrote:
I have an variable of Struct(protobuf) type & now I want it to convert to Map<String, Object> since Jackson is unable to serialise a Struct(protobuf) type object.

I'm not aware of such a util. Most of the consumers of Struct use Struct directly. I think you'd need to write a converter. Seems like a simple recursive converter could be written in, say, ~30 lines of code. Value is very simple, so it'd mainly be a switch on the kind oneof.
Reply all
Reply to author
Forward
0 new messages