Skip to content
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

gson: comparing two strings may fail due to lazy number parsing #66

Closed
liori opened this issue May 14, 2017 · 2 comments
Closed

gson: comparing two strings may fail due to lazy number parsing #66

liori opened this issue May 14, 2017 · 2 comments

Comments

@liori
Copy link

liori commented May 14, 2017

When using gson as the JSON parser dependency, the following test fails despite that it shouldn't:

assertJsonEquals("{\"foo\": 1.0}", "{\"foo\": 1.00}")

This is because gson parser parses numbers lazily: when parsing, it internally stores a string. Then, when serializing, the same string is reused. See the LazilyParsedNumber class.

Switching to moshi helps.

@lukas-krecan-lt
Copy link
Collaborator

Number comparison is described here https://github.com/lukas-krecan/JsonUnit#numeric-comparison. By default numbers are compared as literals so 1.0 is different than 1.00. This changes if you set tolerance (even to 0). Moshi is broken so it behaves differently.

@liori
Copy link
Author

liori commented May 15, 2017

Ah, sorry then. I will keep using moshi then, because this is the behavior I consider correct here.

@liori liori closed this as completed May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants