Uh oh!
There was an error while loading. Please reload this page.
libserialize: encoding non string key map to json silently produces invalid json instead of failing - #19490
Conversation
lifthrasiir
commented
Dec 3, 2014
This seems too "ugly" for normal uses. Can we do better? For example, we may optionally implement (or insert something like |
oli-obk
commented
Dec 3, 2014
i'd prefer keeping it explicit. |
lifthrasiir
commented
Dec 3, 2014
The autoserialization is commonly used for types that are not aware of serialization (but could have been made aware of it). Adding (I have made it clear that this specific issue is subjective, as "ugly" is quoted, but I don't think that making the output format overly unconventional is good in general. If that were a concern we should have used some other format specific to us.) |
alexcrichton
commented
Dec 6, 2014
I agree with @lifthrasiir that this seems like the wrong default. This means that any users encoding a |
oli-obk
commented
Dec 6, 2014
yes, which is the only sensible way for non-string (or not trivially convertable to string) keys. |
alexcrichton
commented
Dec 8, 2014
I think that not serializing maps as maps is such a gotcha that |
sfackler
commented
Dec 8, 2014
I agree with @alexcrichton. I've felt a bit weird with the JSON module's use of |
sfackler
commented
Dec 8, 2014
We also serialize enums with fields in a way that feels a bit shoehorned in. |
oli-obk
commented
Dec 8, 2014
another alternative would be to output invalid json (map key is a json value, not a string), and to require the json serializer to be created with a flag explicitly allowing that. |
oli-obk
commented
Dec 8, 2014
go-lang: http://golang.org/pkg/encoding/json/#Marshal (has flag to convert key to json and escape as string) python: https://docs.python.org/2/library/json.html (convert to string in python-specific format) .net: http://james.newtonking.com/json/help/index.html?topic=html/SerializationGuide.htm other languages can't get their head around one or another way either. I agree now with @alexcrichton, an error in serialization is the right way to go. i'll update this PR. |
oli-obk
commented
Dec 16, 2014
I have tried several schemes:
A few more possible ways to do these checks
|
alexcrichton
commented
Dec 16, 2014
One possible solution would be to set a flag when emitting a string and resetting it in all other emissions, and then after you emit a key if the flag is set you know you emitted a string and otherwise you know that it wasn't a key. The other direction is also fine where you set a flag when emitting a key and then when you emit a type elsewhere it'll check the flag to make sure it's valid |
afd14a6 to
a8929faCompareoli-obk
commented
Dec 16, 2014
That sounds reasonable. panicking -> error reporting will be done in another PR (after Encoder+PrettyEncoder merge) |
alexcrichton
commented
Dec 16, 2014
Awesome, looks great! Could you actually go a head an add a variant to the error enum returned to reflect this new condition? (as opposed to waiting to a further PR) |
a8929fa to
b1f8a41Comparec85de97 to
fa718ddCompareoli-obk
commented
Dec 18, 2014
r? @alexcrichton |
aef867a to
bc0236fComparebc0236f to
66426beCompareoli-obk
commented
Dec 19, 2014
rebased and fixed |
66426be to
d3e903bCompareoli-obk
commented
Dec 23, 2014
fixed unit test, rebased and fixed rebase fallout |
135da92 to
81173a3Compareoli-obk
commented
Jan 9, 2015
phew, good thing it took me so long to get this ready... it doesn't work! |
b3fb183 to
c0490aeCompareoli-obk
commented
Jan 9, 2015
@alexcrichton it is fixed and tested now, i actually messed up the unit test before, that's why the mistake wasn't caught by it. |
oli-obk
commented
Jan 9, 2015
should i squash the fix? |
alexcrichton
commented
Jan 9, 2015
Sure! |
c0490ae to
b262ab5Compareoli-obk
commented
Jan 10, 2015
done |
oli-obk
commented
Jan 11, 2015
@alexcrichton those failures don't seem to be mine, should i rebase or sth? |
Conflicts: src/libserialize/serialize.rs
b262ab5 to
a320149Compareoli-obk
commented
Jan 19, 2015
rebased |
oli-obk
commented
Jan 19, 2015
the only fix required was changing a |
alexcrichton
commented
Jan 19, 2015
bors
commented
Jan 19, 2015
bors
commented
Jan 19, 2015
…s-report fix: Fix panic in progress due to splitting unicode incorrectly
importing object type string key maps is still supported
writing them should be explicit, and can be done as follows
related to #8335, #9028, #9142