OfficeScenarioTests CoopShares+Assets #121
@ -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<BigDecimal> {
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.config;
|
package net.hostsharing.hsadminng.config;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
@ -20,15 +21,11 @@ public class JsonObjectMapperConfiguration {
|
|||||||
public Jackson2ObjectMapperBuilder customObjectMapper() {
|
public Jackson2ObjectMapperBuilder customObjectMapper() {
|
||||||
// HOWTO: add JSON converters and specify other JSON mapping configurations
|
// HOWTO: add JSON converters and specify other JSON mapping configurations
|
||||||
return new Jackson2ObjectMapperBuilder()
|
return new Jackson2ObjectMapperBuilder()
|
||||||
.modulesToInstall(formattedBigDecimalModule())
|
|
||||||
.modules(new JsonNullableModule(), new JavaTimeModule())
|
.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);
|
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimpleModule formattedBigDecimalModule() {
|
|
||||||
final var module = new SimpleModule();
|
|
||||||
module.addDeserializer(BigDecimal.class, new FormattedBigDecimalDeserializer());
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user