The Struct type is similar to some of the other well-known types like
Timestamp and Duration which have their own custom JSON representation (see
here <https://developers.google.com/protocol-buffers/docs/proto3#json>).
I'm afraid there is no easy way to replicate that functionality with a type
other than Struct.

On Fri, Dec 18, 2020 at 6:57 AM John Naylor <[email protected]>
wrote:

> If I copy struct.proto into a different namespace and convert messages
> based on it to JSON, the conversion adds extra maps to the data.
>
> message built using struct.proto:
>
> string_param: {
>  "oid": "HelloWorld",
>  "name": "My nice parameter",
>  "type": "STRING",
>  "readonly": true,
>  "widget": "default",
>  "precision": 2,
>  "value": "Evacuate the studio!"
> }
>
> message built using the same code but in a different namespace:
>
> native_string_param: {
>  "oid": "HelloWorld",
>  "name": "My nice parameter",
>  "type": "STRING",
>  "readonly": true,
>  "widget": "default",
>  "precision": 2,
>  "value": {
>   "string_value": "Evacuate the studio!"
>  }
> }
>
> note the extra "string_value" mapping.
>
> Is there a way to have MessageToJsonString treat the second type of
> message the same way as it does struct.proto ones?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/a62e3285-8951-463b-b424-629f4a43efc1n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/a62e3285-8951-463b-b424-629f4a43efc1n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr7rci6VQw_Jf2ULX9E8%2B0kfZ%2BSpfxf1bwXw8vTGomFvSA%40mail.gmail.com.

Reply via email to