结论:需要返回给前端的API的DTO中的浮点数属性,推荐使用BigDecimal,使用double会有变成科学计数法的问题;
其他情况,rpc通信或者应用间的序列化反序列化传输,double与BigDecimal均可;
BigDecimal初始化请使用 BigDecimal.valueOf(xx),切记用字符串来初始化,保证精度。
I think I found it: On my first search I missed that Jackson serialization had both SerializationFeatures and DeserializationFeatures, and they are a little different. According to http://fasterxml.github.io/jackson-databind/javadoc/2.0.0/com/fasterxml/jackson/databind/DeserializationFeature.html there is a feature called USE_BIG_DECIMAL_FOR_FLOATS
Feature that determines whether JSON floating point numbers are to be deserialized into BigDecimals if only generic type description (either Object or Number, or within untyped Map or Collection context) is available.
So in my case it was basically
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
JsonRpcHttpClient rpcHttpClient = new JsonRpcHttpClient(
mapper,
new URL("the url"),
new HashMap<String, String>());
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://blog.csdn.net/fxtxz2/article/details/109057340
application.properties
spring.jackson.deserialization.USE_BIG_DECIMAL_FOR_FLOATS=true
spring.jackson.serialization.WRITE_BIGDECIMAL_AS_PLAIN=true