zhaoqiaobo
3 months ago
4 changed files with 51 additions and 0 deletions
@ -0,0 +1,26 @@
|
||||
package org.springblade.common.jsonserializer; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* BigDecimal 序列化器 保留2位小数 四舍五入 |
||||
* @Author zqb |
||||
* @Date 2024/10/8 |
||||
**/ |
||||
public class BigDecimalTwoDecimalSerializer extends JsonSerializer<BigDecimal> { |
||||
|
||||
@Override |
||||
public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException { |
||||
if (value != null) { |
||||
gen.writeNumber(value.setScale(2, RoundingMode.HALF_UP)); |
||||
} else { |
||||
gen.writeNull(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue