diff --git a/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberDeserializer.java b/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberDeserializer.java index 283a64280..ee061aa7f 100644 --- a/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberDeserializer.java +++ b/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberDeserializer.java @@ -22,6 +22,7 @@ import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.ParseException; +import java.util.Locale; import java.util.Optional; /** @@ -49,9 +50,10 @@ protected final Optional deserializeFormatted(String jsonValue, boolean final JsonbNumberFormatter numberFormat = getCustomization().getDeserializeNumberFormatter(); //consider synchronizing on format instance or per thread cache. - final NumberFormat format = NumberFormat.getInstance(jsonbContext.getConfigProperties().getLocale(numberFormat.getLocale())); + final NumberFormat format = NumberFormat.getInstance((Locale.ENGLISH)); ((DecimalFormat)format).applyPattern(numberFormat.getFormat()); format.setParseIntegerOnly(integerOnly); + format.setGroupingUsed(false); try { return Optional.of(format.parse(jsonValue)); } catch (ParseException e) { diff --git a/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberSerializer.java b/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberSerializer.java index 88c0082ea..177e55cfa 100644 --- a/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberSerializer.java +++ b/src/main/java/org/eclipse/yasson/internal/serializer/AbstractNumberSerializer.java @@ -19,6 +19,7 @@ import javax.json.stream.JsonGenerator; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.Locale; /** * Common serializer for numbers, using number format. @@ -52,8 +53,9 @@ public AbstractNumberSerializer(Customization customization) { @Override protected void serialize(T obj, JsonGenerator generator, Marshaller marshaller) { if (formatter != null) { - final NumberFormat format = NumberFormat.getInstance(marshaller.getJsonbContext().getConfigProperties().getLocale(formatter.getLocale())); + final NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); ((DecimalFormat)format).applyPattern(formatter.getFormat()); + format.setGroupingUsed(false); generator.write(format.format(obj)); } else { serializeNonFormatted(obj, generator); diff --git a/src/test/java/org/eclipse/yasson/documented/DocumentationExampleTest.java b/src/test/java/org/eclipse/yasson/documented/DocumentationExampleTest.java index ac4f751e5..d6f7592b1 100644 --- a/src/test/java/org/eclipse/yasson/documented/DocumentationExampleTest.java +++ b/src/test/java/org/eclipse/yasson/documented/DocumentationExampleTest.java @@ -358,7 +358,7 @@ public static class Person9 { @JsonbDateFormat("dd.MM.yyyy") public LocalDate birthDate; - @JsonbNumberFormat("#0.00") + @JsonbNumberFormat(value = "###,##0.00", locale = "de-de") public BigDecimal salary; } @@ -367,15 +367,15 @@ public void testDateNumberFormats1() { Person9 p = new Person9(); p.name = "Jason Bourne"; p.birthDate = LocalDate.of(1999, 8, 7); - p.salary = new BigDecimal("123.45678"); + p.salary = new BigDecimal("1234.5678"); Jsonb jsonb = JsonbBuilder.create(); String json = jsonb.toJson(p); - assertEquals("{\"birthDate\":\"07.08.1999\",\"name\":\"Jason Bourne\",\"salary\":\"123.46\"}", json); + assertEquals("{\"birthDate\":\"07.08.1999\",\"name\":\"Jason Bourne\",\"salary\":\"1234.57\"}", json); - Person9 after = jsonb.fromJson("{\"birthDate\":\"07.08.1999\",\"name\":\"Jason Bourne\",\"salary\":\"123.46\"}", Person9.class); + Person9 after = jsonb.fromJson("{\"birthDate\":\"07.08.1999\",\"name\":\"Jason Bourne\",\"salary\":\"1234.57\"}", Person9.class); assertEquals(p.name, after.name); assertEquals(p.birthDate, after.birthDate); - assertEquals(new BigDecimal("123.46"), after.salary); + assertEquals(new BigDecimal("1234.57"), after.salary); } public static class Person10 {