-
Notifications
You must be signed in to change notification settings - Fork 382
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
json: 🐛Fix stack overflow deserializing empty JSON #1293
json: 🐛Fix stack overflow deserializing empty JSON #1293
Conversation
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.
Looks good, a minor suggestion
UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs
Outdated
Show resolved
Hide resolved
Why do you call "token.ToObject(serializer);" inside ReadJson?
|
I think this was bug. I'm guessing a similar approach was intended here, but we should not need to deserialize a second time here and can instead just return I pushed some changes in that direction, take a look |
It's hard to find any official documentation on how to handle errors in deserialization, but I changed it to explicitly throw an exception if it fails to deserialize the JSON. It seems an exception is the convention when trying to deserialize "{}" to |
Throwing a JsonSerializationException in case of an empty json is ok in my eyes. I added the token to the error message. |
Great! JSON tokens can potentially be huge, maybe we should truncate it to a max length of say 100? This example is 50 long: We can also include the full token in the We use this extension method in a separate project, which we could add as an
|
Thanks a lot! Nuget should be out shortly. |
Fixes #1292
The call to "token.ToObject(serializer)" with an empty or invalid json calls
JsonConvert.DeserializeObject
again and results in infinite recursion and stack overflow.Changes
JsonSerializationException
on invalid JSON inUnitsNetIQuantityJsonConverter
Data["JsonToken"]
property.