Merge branch 'master' of https://codeup.aliyun.com/bsdtec/biz-api-cloud
This commit is contained in:
commit
f922ddf09b
8 files changed
+283
-1
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
package com.bsd.pjcloud.common.core.util;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
public class MoneyDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
String text = p.getText();
|
||||
if (text == null || text.isEmpty()) {
|
||||
return 0; // 默认值
|
||||
}
|
||||
BigDecimal yuan = new BigDecimal(text);
|
||||
return yuan.multiply(new BigDecimal(100)).intValue();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.bsd.pjcloud.common.core.util;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class MoneySerializer extends JsonSerializer<Integer> {
|
||||
@Override
|
||||
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value == null) {
|
||||
gen.writeString("0.00"); // 默认值
|
||||
return;
|
||||
}
|
||||
BigDecimal yuan = new BigDecimal(value).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
||||
gen.writeString(yuan.toString());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user