protoreflect
protoreflect copied to clipboard
how to convert dynamic message to json
not able to convert dynamic message to JSON if the dynamic message has any (type and URL)
md := fd.FindMessage(messageName) dm := dynamic.NewMessage(md) err := dm.Unmarshal(protobufMsg) now how can I convert dynamic message to json . this is the doubt
I'm trying to understand the question. Are you saying that, in your example, md
is the message descriptor for google.protobuf.Any
? Or are you saying that protobufMsg
is an encoded google.protobuf.Any
, and you are trying to unmarshal its enclosed data into a dynamic message?
Perhaps a fuller code sample and example input data as well as both what you expected to happen and what you actually saw might help me understand exactly what you're trying to do.
my protomsg containing this field
dynamic message- other_properties:<type_url:"example.com/yaddayaddayadda/" value:"serialized" >
@Khushbukela, I still don't follow. Can you provide a code example with more context and an actual JSON input example, too? And also say what it is you are seeing vs. what you expect to see? Are you getting an error? Is the unmarshaled value incorrect?
You can just call dm.MarshalJSON or dm.MarshalJSONPB.