Skip to content

Specialized transcoding to/from Json for specific types #44

Open
@GoogleCodeExporter

Description

@GoogleCodeExporter
I have a custom DateTimeProto and GuidProto classes that are binary structures 
which is great for talking to an embedded device running protocol buffers in 
C++.

On the C# side, I use the same protocol buffer messages and output Json to a 
web service.  For those specific types, I would like to input/output specific 
strings in standard string formats instead of a structure.

For example, instead Json like 
"CreateDate": {
    "year": 2009,
    "month": 2,
    "day": 11,
    "hour": 10,
    "minute": 35,
    "second": 19,
    "millisecond": 510,
    "kind": "UNSPECIFIED"
}

I want something that jscript libraries can understand (rfc3339) and is compact:
CreateDate : "2009-02-11T10:35:19.510-00:00"

The same for GUID, input/output a string on the Json side and binary numbers on 
the protocol buffers side.  The reason is that a formatted string in Json is 
much more compact and readable than in the structure format.

I have been looking at subclassing JsonFormatReader and JsonFormatWriter to 
implement exceptions for my specific cases.  I'm not sure if this is the 
correct approach or not.  It looks pretty abstract and changing it for such a 
specific case would not be very reusable.

Another option would be to have a "custom format" interface and then add that 
as a partial to the generated DateTimeProto and GuidProto and then skip the 
reading and writing of all the fields and use the interface functions to 
directly handle the serialization and deserialization to/from Json for those 
objects.

Any thoughts?

Original issue reported on code.google.com by [email protected] on 15 May 2012 at 5:24

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions