Add Message.from_json#411
Conversation
|
Please hold off on merging this while I fix the failing tests. I'm also adding a bugfixes for enum fields and JSON. |
|
With this change, This is because the JSON representation of |
| when Array | ||
| ob.map { |value| normalize_json(value) } | ||
| when Hash | ||
| Hash[*ob.flat_map { |key, value| [key.underscore, normalize_json(value)] }] |
There was a problem hiding this comment.
The underscore thing seems like we'd want to make that optional?
| case value | ||
| when String, Symbol | ||
| when String | ||
| if value.encoding == Encoding::ASCII_8BIT |
There was a problem hiding this comment.
Would it make sense to make this configurable at the from_json method? You can specify if your uses Base64 encoded binary blobs? Maybe true by default but allow the caller to turn it off? That way we don't have to guess.
This PR adds a new
Message.from_jsonclass method that turns a JSON string into a message object.It addresses three shortcomings:
fooBarZap) in the JSON are converted to underscore (fooBarZap)bytesfields are Base64 decoded unless they are already in "binary" format. This is because Protobuf's JSON representation uses Base64 encoding for bytes fields.