|
|
|
@ -1,24 +1,29 @@
|
|
|
|
|
package com.ibeetl.admin.core.conf;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.core.Version;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
|
|
import com.fasterxml.jackson.databind.*;
|
|
|
|
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
|
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
|
|
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.BigDecimalFormat;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.jackson.JsonComponent;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public class JasonConfig {
|
|
|
|
@ -84,4 +89,43 @@ public class JasonConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonComponent
|
|
|
|
|
public class BigDecimalSerializer extends JsonSerializer<BigDecimal> implements ContextualSerializer {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonComponent
|
|
|
|
|
public class BigDecimalDeSerializer extends JsonDeserializer<BigDecimal> {
|
|
|
|
|
@Override
|
|
|
|
|
public BigDecimal deserialize(JsonParser jsonParser,
|
|
|
|
|
DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
|
|
|
|
|
|
|
|
|
return new BigDecimal(jsonParser.getText().replaceAll(",",""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|