增加bigDecimalModule

This commit is contained in:
oyo
2026-01-26 19:51:19 +08:00
parent d1acbbce40
commit 0646f39d5e

View File

@@ -5,6 +5,8 @@ import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import java.math.BigDecimal;
public class ObjectMapperFactory { public class ObjectMapperFactory {
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
@@ -18,6 +20,9 @@ public class ObjectMapperFactory {
static { static {
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).configure(Feature.ALLOW_SINGLE_QUOTES, true); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).configure(Feature.ALLOW_SINGLE_QUOTES, true);
SimpleModule bigDecimalModule = new SimpleModule();
bigDecimalModule.addSerializer(BigDecimal.class, new ToStringSerializer());
objectMapper.registerModule(bigDecimalModule);
objectMapper.setDateFormat(new MyDateFormat()); objectMapper.setDateFormat(new MyDateFormat());
} }
} }