proto3-suite
proto3-suite copied to clipboard
Special case JSONPB instances for Google.Protobuf.Wrappers
(From @j6carey)
The proto3 specification says:
"Wrappers use the same representation in JSON as the wrapped primitive type, except that null is allowed and preserved during data conversion and transfer."
and gives these examples:
2, "2", "foo", true, "true", null, 0, …
However, our Haskell implementation does not yet provide such special cases:
HsJSONPB Google.Protobuf.Wrappers> HsJSONPB.toJSONPB (Just (BoolValue True)) HsJSONPB.defaultOptions
Object (fromList [("value",Bool True)])
In order to match the specification, the result should be just Bool True
.
Though we could provide Google.Protobuf.Wrappers
precompiled in our library,
it might be simpler to special case the code generator to spot the wrapper types
and emit custom code for their JSON-related instances.
There is a similar issue with Google.Protobuf.Timestamp
where the json encoding is based on the rfc3339 string format. For what it worth, here is a patch for the generated code: https://github.com/change-metrics/monocle/pull/362/commits/d29f2b87789774610e930be5cfbf2ba0a4003954#diff-e1074028e244819fddeeb7e6ed1318ffd6a41ec81e53de174752f38ceb017eaa .
Would it be possible to add such module directly to proto3-suite
, or should we create a new proto3-suite-google
package?
@TristanCacqueray: I think it would be fine to add support for those standard types in proto3-suite