You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
package com.mh.user.config; |
|
|
|
import com.fasterxml.jackson.core.JsonGenerator; |
|
import com.fasterxml.jackson.core.JsonParser; |
|
import com.fasterxml.jackson.databind.DeserializationContext; |
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
|
import com.fasterxml.jackson.databind.JsonDeserializer; |
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
import com.fasterxml.jackson.databind.module.SimpleModule; |
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
|
import com.mh.user.model.MyBigDecimalDeserializer; |
|
import org.springframework.context.annotation.Bean; |
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import java.io.IOException; |
|
import java.math.BigDecimal; |
|
|
|
/** |
|
* @author LJF |
|
* @version 1.0 |
|
* @project CHWS |
|
* @description 避免使用科学计数算法 |
|
* @date 2026-01-07 14:37:11 |
|
*/ |
|
@Configuration |
|
public class MyJacksonConfig { |
|
|
|
@Bean("customObjectMapper") |
|
public ObjectMapper customObjectMapper() { |
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
// 注册 JavaTimeModule |
|
mapper.registerModule(new JavaTimeModule()); |
|
|
|
// 启用 BigDecimal 作为普通格式输出(避免科学计数法) |
|
mapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); |
|
|
|
// 注册自定义反序列化器 |
|
SimpleModule module = new SimpleModule(); |
|
module.addDeserializer(BigDecimal.class, new MyBigDecimalDeserializer()); |
|
mapper.registerModule(module); |
|
|
|
// 启用 BigDecimal 处理浮点数 |
|
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); |
|
|
|
return mapper; |
|
} |
|
|
|
}
|
|
|