From 650133dda4d1e54223fd85d3cc53df14851084b2 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 30 Nov 2022 20:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20NumberSerializer=20?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jackson/core/databind/NumberSerializer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/NumberSerializer.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/NumberSerializer.java index 2c51f6598..f6ddd3f27 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/NumberSerializer.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/NumberSerializer.java @@ -5,20 +5,26 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import java.io.IOException; + /** - * Long序列化规则 - *

- * 会将超长long值转换为string + * Long 序列化规则 + * + * 会将超长 long 值转换为 string,解决前端 JavaScript 最大安全整数是 2^53-1 的问题 + * + * @author 星语 */ @JacksonStdImpl public class NumberSerializer extends com.fasterxml.jackson.databind.ser.std.NumberSerializer { + private static final long MAX_SAFE_INTEGER = 9007199254740991L; private static final long MIN_SAFE_INTEGER = -9007199254740991L; public static final NumberSerializer INSTANCE = new NumberSerializer(Number.class); + public NumberSerializer(Class rawType) { super(rawType); } + @Override public void serialize(Number value, JsonGenerator gen, SerializerProvider serializers) throws IOException { // 超出范围 序列化位字符串