44import java .math .BigDecimal ;
55import java .math .BigInteger ;
66import java .text .DecimalFormat ;
7+ import java .text .DecimalFormatSymbols ;
8+ import java .util .Locale ;
79
810import org .junit .jupiter .api .Test ;
911
@@ -98,7 +100,7 @@ public BigDecimal getValue() {
98100 }
99101
100102 static class BigDecimalAsStringSerializer extends JsonSerializer <BigDecimal > {
101- private final DecimalFormat df = new DecimalFormat ("0.0" );
103+ private final DecimalFormat df = createDecimalFormatForDefaultLocale ("0.0" );
102104
103105 @ Override
104106 public void serialize (BigDecimal value , JsonGenerator gen , SerializerProvider serializers ) throws IOException {
@@ -107,7 +109,7 @@ public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider se
107109 }
108110
109111 static class BigDecimalAsNumberSerializer extends JsonSerializer <BigDecimal > {
110- private final DecimalFormat df = new DecimalFormat ("0.0" );
112+ private final DecimalFormat df = createDecimalFormatForDefaultLocale ("0.0" );
111113
112114 @ Override
113115 public void serialize (BigDecimal value , JsonGenerator gen , SerializerProvider serializers ) throws IOException {
@@ -219,4 +221,9 @@ public void testCustomSerializationBigDecimalAsNumber() throws Exception {
219221 ObjectMapper mapper = jsonMapperBuilder ().addModule (module ).build ();
220222 assertEquals (a2q ("{'value':2.0}" ), mapper .writeValueAsString (new BigDecimalHolder ("2" )));
221223 }
224+
225+ // default locale is en_US
226+ private static DecimalFormat createDecimalFormatForDefaultLocale (final String pattern ) {
227+ return new DecimalFormat (pattern , new DecimalFormatSymbols (Locale .ENGLISH ));
228+ }
222229}
0 commit comments