Skip to content

Stack overflow when deserializing unexpected JSON values #1003

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

Closed
Muximize opened this issue Dec 29, 2021 · 2 comments
Closed

Stack overflow when deserializing unexpected JSON values #1003

Muximize opened this issue Dec 29, 2021 · 2 comments
Labels

Comments

@Muximize
Copy link
Contributor

When deserializing "malformed", non-round-trip JSON where unexpected values are encountered, a stack overflow occurs.

For example, when deserializing the following JSON to an object where both properties are Power

{
  "ChargePower": {
    "Unit": "PowerUnit.Kilowatt",
    "Value": 11.0
  },
  "DischargePower": 12.0
}

then the latter triggers an infinite loop in this code:

if (valueUnit == null)
{
return token.ToObject<IQuantity>(serializer);
}

I guess there could be a nicer way of handling this. Maybe interpreting the value as the base unit of Power or throwing an exception?

Also, thanks for making this great library! 👍

@lipchev
Copy link
Collaborator

lipchev commented Dec 29, 2021

Yes, indeed - using a default value for missing properties is the way we went in #985 and #990 (WIP - I'll try to get it out for the start of the new year).
Not sure how to deal with the existing converter- I guess an exception should be thrown somewhere along the way..

@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 2, 2022
@stale stale bot closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants