Code review: JSON unmarshaller
Tyler Jameson Little
beatgammit at gmail.com
Wed Oct 17 10:39:36 PDT 2012
I could make my marshaller/unmarshaller only update objects in
place. I think this is more useful and would remove the overlap
between orange and the JSON library. We could then write a JSON
archiver for orange and include it in std.json as well.
The call to unmarshal would look like:
bool unmarshalJSON(T)(JSONValue val, out T ret);
The following restrictions would apply:
* T must be fully instantiated (all pointers are valid [not null])
* T must not be recursive (results in infinite recursion, and
hence stack overflow)
And the marshaller:
JSONValue marshalJSON(T)(in T val);
For marshalling, the restrictions are:
* Slices are handled as if they were an array (copy all values)
* Same as unmarshaller, except null pointers will be treated as
JSON null
I really like Go's JSON marshaller/unmarshaller, so I'm trying to
model after that one. It allows updating an object in place,
which was already a goal.
There should probably be some standard D serialization format. In
working with a structure trained on data (for machine learning,
natural language processing, etc), a complete serialization
solution makes sense. But for simple data passing, JSON makes a
lot of sense.
What do you think, do you think there's a place in Phobos for a
simple JSON marshaller/unmarshaller?
I'll have some updated code soon, and I'll post back when that's
done, in case you'd like to have a look.
More information about the Digitalmars-d-learn
mailing list