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

[BUG] Decimal conversion in toJsonString depends on system locale and uses wrong separator #365

Open
ivan-nazarenko opened this issue Jan 19, 2024 · 0 comments

Comments

@ivan-nazarenko
Copy link

The json specification requires a "." for decimal separator: https://www.json.org/json-en.html

toJsonString uses "," for decimal separator for some system locales like German or Spanish

Test to reproduce the issue:

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DecimalPointFormattingTest {

    @Test
    void formatsNumbersWithDecimalDot() {
        Locale.setDefault(Locale.GERMAN);
        Map fields = new HashMap<String, Object>();
        fields.put("number", 1.1);

        com.beust.klaxon.JsonObject json = new com.beust.klaxon.JsonObject(fields);

        String string = json.toJsonString(false, true);
        assertEquals("{\"number\":1.1E0}", string);
    }

}
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

1 participant