diff --git a/hutool-json/pom.xml b/hutool-json/pom.xml
index 5c1d63446..34a39eb72 100755
--- a/hutool-json/pom.xml
+++ b/hutool-json/pom.xml
@@ -41,6 +41,12 @@
${bouncycastle.version}
test
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.24
+ test
+
diff --git a/hutool-json/src/main/java/cn/hutool/json/InternalJSONUtil.java b/hutool-json/src/main/java/cn/hutool/json/InternalJSONUtil.java
index a8931d3ad..26da40e64 100755
--- a/hutool-json/src/main/java/cn/hutool/json/InternalJSONUtil.java
+++ b/hutool-json/src/main/java/cn/hutool/json/InternalJSONUtil.java
@@ -17,7 +17,7 @@ import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.serialize.GlobalSerializeMapping;
import cn.hutool.json.serialize.JSONDeserializer;
-import cn.hutool.json.serialize.JSONString;
+import cn.hutool.json.serialize.JSONStringer;
import cn.hutool.json.writer.GlobalValueWriterMapping;
import cn.hutool.json.writer.JSONValueWriter;
@@ -63,7 +63,7 @@ public final class InternalJSONUtil {
}
if (object instanceof JSON //
- || object instanceof JSONString //
+ || object instanceof JSONStringer //
|| object instanceof CharSequence //
|| object instanceof Number //
|| ObjUtil.isBasicType(object) //
@@ -117,8 +117,8 @@ public final class InternalJSONUtil {
/**
* 值转为String,用于JSON中。规则为:
*
- * - 对象如果实现了{@link JSONString}接口,调用{@link JSONString#toJSONString()}方法
- * - 对象如果实现了{@link JSONString}接口,调用{@link JSONString#toJSONString()}方法
+ * - 对象如果实现了{@link JSONStringer}接口,调用{@link JSONStringer#toJSONString()}方法
+ * - 对象如果实现了{@link JSONStringer}接口,调用{@link JSONStringer#toJSONString()}方法
* - 对象如果是数组或Collection,包装为{@link JSONArray}
* - 对象如果是Map,包装为{@link JSONObject}
* - 对象如果是数字,使用{@link NumberUtil#toStr(Number)}转换为字符串
@@ -133,9 +133,9 @@ public final class InternalJSONUtil {
if (value == null) {
return StrUtil.NULL;
}
- if (value instanceof JSONString) {
+ if (value instanceof JSONStringer) {
try {
- return ((JSONString) value).toJSONString();
+ return ((JSONStringer) value).toJSONString();
} catch (final Exception e) {
throw new JSONException(e);
}
diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONNumber.java b/hutool-json/src/main/java/cn/hutool/json/JSONNumber.java
new file mode 100755
index 000000000..fd70a85c6
--- /dev/null
+++ b/hutool-json/src/main/java/cn/hutool/json/JSONNumber.java
@@ -0,0 +1,81 @@
+package cn.hutool.json;
+
+import cn.hutool.core.lang.mutable.MutableEntry;
+import cn.hutool.core.math.NumberUtil;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.function.Predicate;
+
+/**
+ * JSON数字表示
+ *
+ * @author looly
+ * @since 6.0.0
+ */
+public class JSONNumber extends Number implements JSON {
+ private static final long serialVersionUID = 1L;
+
+ private final Number value;
+ /**
+ * 配置项
+ */
+ private final JSONConfig config;
+
+ /**
+ * 构造
+ *
+ * @param value 值
+ * @param config JSON配置
+ */
+ public JSONNumber(final Number value, final JSONConfig config) {
+ this.value = value;
+ this.config = config;
+ }
+
+ @Override
+ public JSONConfig getConfig() {
+ return this.config;
+ }
+
+ @Override
+ public int size() {
+ return 1;
+ }
+
+ @Override
+ public Writer write(final Writer writer, final int indentFactor, final int indent,
+ final Predicate> predicate) throws JSONException {
+ try {
+ writer.write(toString());
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ return writer;
+ }
+
+ @Override
+ public int intValue() {
+ return this.value.intValue();
+ }
+
+ @Override
+ public long longValue() {
+ return this.value.longValue();
+ }
+
+ @Override
+ public float floatValue() {
+ return this.value.floatValue();
+ }
+
+ @Override
+ public double doubleValue() {
+ return this.value.doubleValue();
+ }
+
+ @Override
+ public String toString() {
+ return NumberUtil.toStr(this.value);
+ }
+}
diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONString.java b/hutool-json/src/main/java/cn/hutool/json/JSONString.java
new file mode 100755
index 000000000..435947307
--- /dev/null
+++ b/hutool-json/src/main/java/cn/hutool/json/JSONString.java
@@ -0,0 +1,76 @@
+package cn.hutool.json;
+
+import cn.hutool.core.lang.mutable.MutableEntry;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.function.Predicate;
+
+/**
+ * JSON字符串,表示一个字符串
+ *
+ * @author looly
+ * @since 6.0.0
+ */
+public class JSONString implements JSON, CharSequence {
+ private static final long serialVersionUID = 1L;
+
+ private final char[] value;
+ /**
+ * 配置项
+ */
+ private final JSONConfig config;
+
+ /**
+ * 构造
+ *
+ * @param value char数组
+ * @param config 配置项
+ */
+ public JSONString(final char[] value, final JSONConfig config) {
+ this.value = value;
+ this.config = config;
+ }
+
+ @Override
+ public JSONConfig getConfig() {
+ return this.config;
+ }
+
+ @Override
+ public int size() {
+ return length();
+ }
+
+ @Override
+ public Writer write(final Writer writer, final int indentFactor, final int indent,
+ final Predicate> predicate) throws JSONException {
+ try {
+ writer.write(this.value);
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ return writer;
+ }
+
+ @Override
+ public int length() {
+ return this.value.length;
+ }
+
+ @Override
+ public char charAt(final int index) {
+ return this.value[index];
+ }
+
+ @Override
+ public CharSequence subSequence(final int start, final int end) {
+ return ((start == 0) && (end == this.value.length)) ? this
+ : new String(this.value, start, end);
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.value);
+ }
+}
diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONSupport.java b/hutool-json/src/main/java/cn/hutool/json/JSONSupport.java
index 2f6ea18a2..7733f5dfb 100644
--- a/hutool-json/src/main/java/cn/hutool/json/JSONSupport.java
+++ b/hutool-json/src/main/java/cn/hutool/json/JSONSupport.java
@@ -2,7 +2,7 @@ package cn.hutool.json;
import cn.hutool.core.bean.copier.BeanCopier;
import cn.hutool.json.serialize.JSONDeserializer;
-import cn.hutool.json.serialize.JSONString;
+import cn.hutool.json.serialize.JSONStringer;
/**
* JSON支持
@@ -10,7 +10,7 @@ import cn.hutool.json.serialize.JSONString;
*
* @author Looly
*/
-public class JSONSupport implements JSONString, JSONDeserializer