Usage of custom class with JSONValue

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 24 10:03:25 PDT 2016


On Thursday, 24 March 2016 at 16:03:13 UTC, Edwin van Leeuwen 
wrote:
> On Thursday, 24 March 2016 at 11:39:13 UTC, arturg wrote:
>> isnt alias this supposed to do this implicitly?
>>
>> convert this
>> auto jsValue = JSONValue(new MyClass());
>>
>> into this
>> auto jsValue = JSONValue((new MyClass())._data);
>
> Good point, I did not catch that. That indeed should work and 
> seems to be a bug. Does it work if _data is a base type (string 
> or int, etc..)

Thanks for the answers. I also wonder why alias this does not the 
job.
Unfortunatelly even if it works, the _data is not the data I want 
to be used
as value for JSONValue. _data only contains keys, the values are 
stored
in another variable. JSONValue should contain both.

I hoped there is some operator overloading for implicit 
conversion of my
class to JSONValue.
I solved the issue with an toJSON method and a generic 
functionality which
checks for this method.

Kind regards
André


More information about the Digitalmars-d-learn mailing list