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
v10: De-serialization of Decimal fails when there is no leading zero #1510
Comments
|
ok, but it worked in the prior versions. I entirely understand making the serializer output correct JSON but limiting the deserializer in this way means that any stored data is now broken. Also, incidentally, if you change Decimal to Double then it still works fine with ".1" |
Ahh, if it used to work then it should probably accept such invalid input as long as it doesn't cause it to somehow do the wrong thing on valid input. |
See here for a discussion of this when the optimized double parsing was in the works for Json.NET 10.0 which was then rolled back due to double precision issues when parsing. The same parsing logic was used in the optimized decimal parsing PR for Json.NET 10.0 which has not been rolled back. |
Just to be clear, we are sacrificing backwards compatibility for speed with v10 and there is no plan to make this work as it used to in v9? So we need to to change our code to deal with this before we upgrade to 10+ |
To quote @JamesNK
The parser could easily be updated to accept leading periods and maintain the performance improvements but it was considered a bug by James that it supported parsing those values before. Yes, you'll need to change your code to deal with this before you upgrade to 10+ perhaps by just reading in the json and immediately writing it back out which should fix the formatting. |
It's not just code though. Any serialized, persisted data will now by broken too.
So every application out there has to be slowed down with unnecessary writes just so the library can remain "pure". And that's not to mention the huge amount of work involved in implementing those write backs and testing to ensure that we've caught them all. I agree with James, it is a bug, but breaking behaviour which has been around for a long time is bad. If there were a significant performance hit in supporting the "wrong" way then I could maybe see it but if, as you say, support is inexpensive performance wise then why break anything? |
I agree with you but that wasn't my call. |
Hmmm, I'm torn on one vs the other. You really shouldn't have number values that start with a decimal point - they won't work with any other JSON framework - but on the other hand it isn't difficult to parse those values. |
Are there any other frameworks these days? Your's is pretty much the de facto standard. ;-) |
Maybe we could have strict setting that we could set to false. |
@Richard-Payne there are a couple of JSON frameworks out there.
And there are additional new Json implementations: |
@JamesNK did this ever get looked at? |
Source/destination types
Source/destination JSON
Expected behavior
Expect num = 0.1
Actual behavior
Newtonsoft.Json.JsonReaderException: Input string '.1' is not a valid decimal
Steps to reproduce
Works fine with v9 but fails in v10.
The text was updated successfully, but these errors were encountered: