签到汇总
parent
197e22ffe8
commit
f29bb65620
@ -0,0 +1,23 @@
|
|||||||
|
package com.ibeetl.admin.core.conf;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import org.springframework.boot.jackson.JsonComponent;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@JsonComponent
|
||||||
|
public class BigDecimalDeSerializer extends JsonDeserializer<BigDecimal> {
|
||||||
|
|
||||||
|
public BigDecimalDeSerializer() {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public BigDecimal deserialize(JsonParser jsonParser,
|
||||||
|
DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
|
return new BigDecimal(jsonParser.getText().replaceAll(",",""));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.ibeetl.admin.core.conf;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.BeanProperty;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||||
|
import com.ibeetl.admin.core.annotation.BigDecimalFormat;
|
||||||
|
import org.springframework.boot.jackson.JsonComponent;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@JsonComponent
|
||||||
|
public class BigDecimalSerializer extends JsonSerializer<BigDecimal> implements ContextualSerializer {
|
||||||
|
|
||||||
|
public BigDecimalSerializer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private String format = "#####0.00";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||||
|
jsonGenerator.writeString(new DecimalFormat(format).format(bigDecimal));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException {
|
||||||
|
if(beanProperty !=null ){
|
||||||
|
if(Objects.equals(beanProperty.getType().getRawClass(),BigDecimal.class)){
|
||||||
|
BigDecimalFormat bigDecimalFormat = beanProperty.getAnnotation((BigDecimalFormat.class));
|
||||||
|
if(bigDecimalFormat == null){
|
||||||
|
bigDecimalFormat = beanProperty.getContextAnnotation(BigDecimalFormat.class);
|
||||||
|
}
|
||||||
|
BigDecimalSerializer bigDecimalSerializer = new BigDecimalSerializer();
|
||||||
|
if(bigDecimalFormat != null){
|
||||||
|
bigDecimalSerializer.format = bigDecimalFormat.value();
|
||||||
|
}
|
||||||
|
return bigDecimalSerializer;
|
||||||
|
}
|
||||||
|
return serializerProvider.findValueSerializer(beanProperty.getType(),beanProperty);
|
||||||
|
}
|
||||||
|
return serializerProvider.findNullValueSerializer(beanProperty);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue