does MessageToJsonString give special treatment to struct.proto messages?

33 views
Skip to first unread message

John Naylor

unread,
Dec 18, 2020, 9:57:10 AM12/18/20
to Protocol Buffers
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!

Adam Cozzette

unread,
Dec 21, 2020, 1:32:59 PM12/21/20
to John Naylor, Protocol Buffers
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). I'm afraid there is no easy way to replicate that functionality with a type other than Struct.

--
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 protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/a62e3285-8951-463b-b424-629f4a43efc1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages