Skip to content

Conversation

@Ikiselev7
Copy link

In some cases we found the problem. If we try to parse Double from json like 0.12345678912345678 parser return BigDecimal value, and matchers return assertion failure, but this number can be parse to Double. Spring test use your library and we found that problem there. I was add test value to TestFloat class and write some solution in JSONParserBase extractFloat method for that case. I think the solution isn't good, but now I don't know how I can fix it better.

return Double.parseDouble(xs);
double value = Double.parseDouble(xs);
if (xs.length() > 18) { // follow JSonIJ parsing method
if(!String.valueOf(value).equals(xs)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like that that will rune performances ...
it's obvious that a number with 50 number will be a big decimal.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem here, it just compare the string equlas, but ignore the case of e E e+ E+

@UrielCh
Copy link
Contributor

UrielCh commented Apr 1, 2021

I have just add the following test:

	public void testPrecisionFloat() throws Exception {
		JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
		for (int len = 15; len < 25; len++) {
			StringBuilder sb = new StringBuilder("0.");
			for (int i = 0; i < len; i++) {
				sb.append("123456789".charAt(i % 9));
			}
			String s = sb.toString();
			String json = "{v:" + s + "}";
			JSONObject obj = (JSONObject) p.parse(json);
			Object value = obj.get("v").toString();
			assertEquals("Should not loose precision on a " + len + " digits long", s, value);
		}
	}

and it pass...

@UrielCh
Copy link
Contributor

UrielCh commented Apr 1, 2021

use a custom flag and do not select USE_HI_PRECISION_FLOAT

for example
MODE_RFC4627 = USE_INTEGER_STORAGE | USE_HI_PRECISION_FLOAT | ACCEPT_TAILLING_SPACE;

user

MODE_MY = USE_INTEGER_STORAGE | ACCEPT_TAILLING_SPACE;

@UrielCh UrielCh closed this Apr 1, 2021
@UrielCh
Copy link
Contributor

UrielCh commented Apr 1, 2021

After some reflection, I have added the flag:
BIG_DIGIT_UNRESTRICTED, to deal with your issue.

@UrielCh UrielCh reopened this Apr 1, 2021
@UrielCh UrielCh added the in progress a fix is in progresse. label Apr 1, 2021
@UrielCh UrielCh added this to the 2.3 milestone Apr 1, 2021
@UrielCh
Copy link
Contributor

UrielCh commented Apr 24, 2021

fixed by adding BIG_DIGIT_UNRESTRICTED flag.

@UrielCh UrielCh closed this Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in progress a fix is in progresse.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants