4
4
import java .math .BigDecimal ;
5
5
import java .math .BigInteger ;
6
6
import java .text .DecimalFormat ;
7
+ import java .text .DecimalFormatSymbols ;
8
+ import java .util .Locale ;
7
9
8
10
import org .junit .jupiter .api .Test ;
9
11
@@ -98,7 +100,7 @@ public BigDecimal getValue() {
98
100
}
99
101
100
102
static class BigDecimalAsStringSerializer extends JsonSerializer <BigDecimal > {
101
- private final DecimalFormat df = new DecimalFormat ("0.0" );
103
+ private final DecimalFormat df = createDecimalFormatForDefaultLocale ("0.0" );
102
104
103
105
@ Override
104
106
public void serialize (BigDecimal value , JsonGenerator gen , SerializerProvider serializers ) throws IOException {
@@ -107,7 +109,7 @@ public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider se
107
109
}
108
110
109
111
static class BigDecimalAsNumberSerializer extends JsonSerializer <BigDecimal > {
110
- private final DecimalFormat df = new DecimalFormat ("0.0" );
112
+ private final DecimalFormat df = createDecimalFormatForDefaultLocale ("0.0" );
111
113
112
114
@ Override
113
115
public void serialize (BigDecimal value , JsonGenerator gen , SerializerProvider serializers ) throws IOException {
@@ -219,4 +221,9 @@ public void testCustomSerializationBigDecimalAsNumber() throws Exception {
219
221
ObjectMapper mapper = jsonMapperBuilder ().addModule (module ).build ();
220
222
assertEquals (a2q ("{'value':2.0}" ), mapper .writeValueAsString (new BigDecimalHolder ("2" )));
221
223
}
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
+ }
222
229
}
0 commit comments