Code review: JSON unmarshaller

Ali Çehreli acehreli at yahoo.com
Tue Oct 16 01:05:26 PDT 2012


On 10/15/2012 12:03 PM, Tyler Jameson Little wrote:

 >I did my best in grokking
 > std.traits, but I may have missed some subtleties about what the
 > templates are actually testing.

You have mentioned needing an allMembers that excluded functions in one 
of your other posts. The following thread was exactly about that. I can 
never remember the solution, but I found it again: :)

 
http://www.digitalmars.com/d/archives/digitalmars/D/learn/Getting_only_the_data_members_of_a_type_34086.html

(Although JSON is not mentioned in there, that thread has been inspired 
by marshalling as well. :))

 > I used asserts and contracts to validate input, so the following would
 > throw an AssertError:
 >
 > int x = unmarshalJSON!int(`"5"`);

std.exception.enforce is the right choice in that case. You don't want 
the checks to disappear when asserts are turned off.

 > I wasn't sure if this is bad style, since AssertError is in
 > core.exception. If this is considered bad style in D, I can create a
 > JSONMarshalException and throw that instead.

That makes sense too. There is enforceEx() to throw a specific type of 
exception.

Ali



More information about the Digitalmars-d-learn mailing list