proto3-suite icon indicating copy to clipboard operation
proto3-suite copied to clipboard

Special case JSONPB instances for Google.Protobuf.Wrappers

Open themattchan opened this issue 5 years ago • 2 comments

(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.

themattchan avatar May 21 '19 00:05 themattchan

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 avatar May 07 '21 11:05 TristanCacqueray

@TristanCacqueray: I think it would be fine to add support for those standard types in proto3-suite

Gabriella439 avatar May 07 '21 19:05 Gabriella439