Closed dumblob closed 9 years ago
IMHO, any key type should be allowed and if it's not one of the out-of-box serializable types, again, the code section should be called.
Btw, the error Non-string key in map/object
should be more descriptive - at least say which type was the non-string
key of.
Supporting arbitrary keys is problematic because the code section for json::serialize()
is not fitted for handling object keys (the return type is required to be different for this case).
For now, I just changed it so that a map with non-string keys is passed to the code section as a whole. You can then .associate()
it to anything appropriate. And thus those error message should no longer pop up.
Unless there are other suggestions, I think there is nothing else to do on this issue.
load web.json
y = {
(enum<a,b>)$a -> 5,
$b -> 7,
}
io.writeln(
json.serialize(y) { [obj]
switch (obj) type {
#case map<enum, @V>: # why doesn't this match the object?
case map<@K, @V>:
return (json.Data)obj.associate { ( ((string)X)[1:], (int)Y ) }
default:
return (json.Data)"some mistake!"
}
}
)
{
{
"a": 5,
"b": 7
}
I'd expect only one opening curly bracket and the $pretty
indentation should be probably the same for opening and closing bracket.
Fixed.
Any map is considered as
map<string, any>
and if the key is notstring
, the whole map is considered unserializable, which is a wrong assumption.