-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for enums (or other string convertable types) as keys to m... #333
Conversation
…o maps for json serialization
Thanks, this is a good idea. The only thing that needs to be rebalanced now a bit is serialization vs. deserialization. The idea is that anything that can be serialized must also be deserializable, so a check is needed in Should you be willing to extend it prior to pulling, that would be great! Otherwise I can pull it and do the rest of the changes myself (probably early next week). |
Great, thanks. Good ideas - I'll certainly give it a go and see if I can extend as you suggest.
|
improve serialization of AA to serialize if possible, skip otherwise
} else static if(isStringSerializable!(TK)) { | ||
ret[key.toString()] = serializeToJson(value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is very wrong with whitespaces in this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't quite understand it... I think it looks ok in the source:
https://github.com/patefacio/vibe.d/blob/master/source/vibe/data/json.d
}elsestaticif(isAssociativeArray!T){ aliastypeof(T.init.values[0])TV; aliasKeyType!TTK; Unqual!TV[TK]dst; foreach(stringkey,value;src){ staticif(is(TK==string)){ dst[key]=deserializeJson!(Unqual!TV)(value); }elsestaticif(is(TK==enum)){ dst[to!(TK)(key)] = deserializeJson!(Unqual!TV)(value); }elsestaticif(isStringSerializable!TK){ autodsk=TK.fromString(key); dst[dsk]=deserializeJson!(Unqual!TV)(value); } } returndst;
From: Михаил Страшун [email protected]
To: rejectedsoftware/vibe.d [email protected]
Cc: Daniel Davidson [email protected]
Sent: Thursday, October 3, 2013 9:31 AM
Subject: Re: [vibe.d] added support for enums (or other string convertable types) as keys to m... (#333)In source/vibe/data/json.d:
@@ -899,8 +899,16 @@ Json serializeToJson(T)(T value)
return Json(ret);
} else static if( isAssociativeArray!TU ){
Json[string] ret;
foreach( string key, value; value )
ret[key] = serializeToJson(value);
alias KeyType!T TK;
foreach( key, value; value ) {
static if(is(TK == string)) {
ret[key] = serializeToJson(value);
} else static if(is(TK == enum)) {
ret[to!string(key)] = serializeToJson(value);
} else static if(isStringSerializable!(TK)) {
ret[key.toString()] = serializeToJson(value);
}
Something is very wrong with whitespaces in this block.}
—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've used spaces rather than tabs. Don't you use an editor that visualize tabs? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Selecting text in github shows there are spaces in this code, while tabs everywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked source file as-is and it has tabs with extra trailing single space. Maybe that is what confuses github.
Looks good as far as I can see. I'll double check the whitespace after merging. The display on GitHub is often strange and I generally completely ignore that and look at the actual code instead. It's a nice opportunity for improvement, though. Is there a public issue tracker for github itself somewhere? |
added support for enums (or other string convertable types) as keys to m...
Not I am aware of. |
No worries on this though, it was my fault. There were indent issues (I was looking at the wrong place). Thanks
|
...aps for json serialization