From 83adb7a5aed3ba9ca2c880db1be790e718144e5f Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 14 Nov 2024 15:11:15 +0100 Subject: [PATCH] remove FormattedBigDecimalDeserializer, did not work anyway --- .../FormattedBigDecimalDeserializer.java | 28 ------------------- .../config/JsonObjectMapperConfiguration.java | 13 ++++----- 2 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/net/hostsharing/hsadminng/config/FormattedBigDecimalDeserializer.java diff --git a/src/main/java/net/hostsharing/hsadminng/config/FormattedBigDecimalDeserializer.java b/src/main/java/net/hostsharing/hsadminng/config/FormattedBigDecimalDeserializer.java deleted file mode 100644 index 10991b15..00000000 --- a/src/main/java/net/hostsharing/hsadminng/config/FormattedBigDecimalDeserializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.hostsharing.hsadminng.config; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import java.io.IOException; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.Locale; - -public class FormattedBigDecimalDeserializer extends JsonDeserializer { - - @Override - public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - final var numberStr = p.getText(); - try { - final var format = NumberFormat.getInstance(Locale.GERMANY); - if (format instanceof DecimalFormat) { - ((DecimalFormat) format).setParseBigDecimal(true); - } - return (BigDecimal) format.parse(numberStr); - } catch (final ParseException e) { - throw new IOException("Failed to parse BigDecimal from string: " + numberStr, e); - } - } -} diff --git a/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java b/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java index 1afa7ed8..d7d535c3 100644 --- a/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java +++ b/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.config; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; @@ -20,15 +21,11 @@ public class JsonObjectMapperConfiguration { public Jackson2ObjectMapperBuilder customObjectMapper() { // HOWTO: add JSON converters and specify other JSON mapping configurations return new Jackson2ObjectMapperBuilder() - .modulesToInstall(formattedBigDecimalModule()) .modules(new JsonNullableModule(), new JavaTimeModule()) - .featuresToEnable(JsonParser.Feature.ALLOW_COMMENTS, JsonParser.Feature.ALLOW_COMMENTS) + .featuresToEnable( + JsonParser.Feature.ALLOW_COMMENTS, + DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS + ) .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); } - - private SimpleModule formattedBigDecimalModule() { - final var module = new SimpleModule(); - module.addDeserializer(BigDecimal.class, new FormattedBigDecimalDeserializer()); - return module; - } }