|
@@ -3,6 +3,7 @@ package cn.superdesk.uniorder.common.json.deserializer;
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -18,6 +19,7 @@ import java.util.Objects;
|
|
* @UpdateRemark: 修改内容
|
|
* @UpdateRemark: 修改内容
|
|
* @Version: 1.0
|
|
* @Version: 1.0
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
public class BigDecimalScale2ConvertDeserializer extends JsonDeserializer<BigDecimal> {
|
|
public class BigDecimalScale2ConvertDeserializer extends JsonDeserializer<BigDecimal> {
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -30,14 +32,19 @@ public class BigDecimalScale2ConvertDeserializer extends JsonDeserializer<BigDec
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public BigDecimal deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
|
public BigDecimal deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
|
-
|
|
|
|
- if (Objects.isNull(jsonParser.getDecimalValue())) {
|
|
|
|
|
|
+ String text = jsonParser.getText();
|
|
|
|
+ if (Objects.isNull(text) || text.trim().isEmpty()) {
|
|
// return null;
|
|
// return null;
|
|
return BigDecimal.ZERO;
|
|
return BigDecimal.ZERO;
|
|
} else {
|
|
} else {
|
|
// 这里取floor
|
|
// 这里取floor
|
|
- return jsonParser.getDecimalValue().setScale(2, RoundingMode.FLOOR);
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ return new BigDecimal(text).setScale(2, RoundingMode.FLOOR);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("decimal数据格式转换异常,text: {}", text);
|
|
|
|
+ throw new RuntimeException("decimal数据格式转换异常");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|