-
Notifications
You must be signed in to change notification settings - Fork 4.7k
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
DataContractJsonSerializer incompatible with ES6 (and V8) #16204
Comments
I think an ES6 compatible way to ToString double and floats would be useful beyond just DataContractJsonSerializer. |
Thanks for the suggestion, @JamesNK . That seems reasonable to me. I opened https://github.com/dotnet/corefx/issues/6405 for tracking this. DataContractJsonSerializer converts a double value to string by calling, value.ToString("R", NumberFormatInfo.InvariantInfo) |
That is what Json.NET does as well. |
If you look into the published .NET code in the initial bug report, there are other incompatibility issues as well. My wish is to be able to use the following with .NET: |
@cyberphone can you please direct me to the spec for the following point? Thanks.
|
Hi @shmao All browsers do this so it can't be completely wrong :-) Anyway, it is a prerequisite for "predictable serialization" which is what you need for interoperable in-object JSON signatures. |
Thanks for the info, @cyberphone . According to Note 3 in section 24.3.2,
Serializing "\u000a" into ""\u000a"" seems correct, right? |
@shmao The spec says or with the shorter forms which seems like an alternative. And it is OK according to the JSON spec. But the following lines say different things: 24.3.2.2 Runtime Semantics: QuoteJSONString ( value )
|
Thanks for pointing out that, @cyberphone. I will take a look at this. |
I'm not sure how to escape 0x000B. According to the spec, 0x000B (LINE TABULATION) should be serialized as \t. But 0x000B is \v not \t. Escaping it to \t wouldn't make a round trip. |
@shmao Whow! You have found a bug in the spec. JSON only talks about \t (0009) so that's the one we care about. \v should be serialized as \u000b. |
Having looked around a bit it seems that the JSON world is rather divided and needs to consider supporting two different serializations, one which is ES6-compatible and another which is ES6-compatible but properly escaped to be declared in browser as a JavaScript object. The latter means that '<', '>', and '&' must be expressed as \unnnn. Preferably quotes around identifier-compatible property names are also dropped in the JavaScript mode. |
@cyberphone , thanks for the additional info. Can you please point me to the specs for these two different requirements? Sorry for the late response, I am busy with some other issues recently. |
@shmao Well, "on the wire" only real JSON encoding makes sense, but if you express JSON as a JavaScript object embedded in an HTML page like this var jsonData = {
myprop: "</script>"
}; it will break in a browser so I made (in my Java tools...), JavaScript a serializer option that:
The cool thing is that JSON.stringify() is unaffected by this change since it using ES6 restores data to its true JSON format! |
The fix for serializing control characters has been merged. dotnet/corefx#6665 I think we should open a new issue for the above suggestion, escaping '<', '>', and '&', and etc as this issue is for tracking DataContractJsonSerializer being incompatible with ES6. |
Opened dotnet/corefx#7416 for tracking the above suggestion. |
Bug report with code:
https://github.com/cyberphone/jsondotnet
The text was updated successfully, but these errors were encountered: