compile time introspection and code generation - automatically serialize to json

Tobias Pankrath tobias at pankrath.net
Thu Jul 21 00:57:00 PDT 2011


Hi everyone,

I'm taking a look at D again and asked myself, if 
it is possible to write a template mixin or something
similiar that automatically serializes an object to json.

For example:

class MyClass 
{
    string memberA;
    int memberB;
    MyClass memberC;
    mixin ToJson!MyClass;
}

should make possible to automatically output
"someid" { "memberA" : "somestring", 
	"memberB" : 12,
	memberC : "someotherid"};

How could this be accomplished? I've found std.traits
RepresentationTypeTupel but don't see how this would
help me. 

Thanks, 

Tobias

 


More information about the Digitalmars-d-learn mailing list