From f020aa623de57d4dc4be234122565c66df4d1bdd Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 15:02:19 +0800 Subject: [PATCH 01/26] check child is json or not.it will be continue if not. --- .../dubbo/registry/zookeeper/ZookeeperRegistry.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 4052df8d262..94301979b37 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -46,6 +46,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_ERROR_DESERIALIZE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; @@ -201,6 +202,14 @@ public void doSubscribe(final URL url, final NotifyListener listener) { ChildListener zkListener = ConcurrentHashMapUtils.computeIfAbsent( listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { + if (child.startsWith("{") || child.endsWith("}")){ + logger.warn(PROTOCOL_ERROR_DESERIALIZE, + "", + "", + child + + "is not json"); + continue; + } child = URL.decode(child); if (!anyServices.contains(child)) { anyServices.add(child); From d6042b2de01c6d1c62af492fc910b330edc78494 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 16:13:56 +0800 Subject: [PATCH 02/26] try to save code format problem. --- .../dubbo/registry/zookeeper/ZookeeperRegistry.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 94301979b37..c87c5add99d 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -202,12 +202,8 @@ public void doSubscribe(final URL url, final NotifyListener listener) { ChildListener zkListener = ConcurrentHashMapUtils.computeIfAbsent( listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { - if (child.startsWith("{") || child.endsWith("}")){ - logger.warn(PROTOCOL_ERROR_DESERIALIZE, - "", - "", - child - + "is not json"); + if (!child.startsWith("{") || !child.endsWith("}")) { + logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); continue; } child = URL.decode(child); From cd2cc5170208a2114144bd890c439df254f7f9fe Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 16:58:07 +0800 Subject: [PATCH 03/26] child could be json array.so child could start with { or [. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index c87c5add99d..048058ebcce 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -202,7 +202,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { ChildListener zkListener = ConcurrentHashMapUtils.computeIfAbsent( listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { - if (!child.startsWith("{") || !child.endsWith("}")) { + if (!child.startsWith("{") && !child.startsWith("[")) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); continue; } From d95f7579954369a0b99babf48e5cc053c3da1dc4 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 20:11:39 +0800 Subject: [PATCH 04/26] fix the problem of it will continue some message to make zookeeper outtime. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 048058ebcce..57017564657 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -204,7 +204,6 @@ public void doSubscribe(final URL url, final NotifyListener listener) { for (String child : currentChildren) { if (!child.startsWith("{") && !child.startsWith("[")) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); - continue; } child = URL.decode(child); if (!anyServices.contains(child)) { From 96298d860fd7d40a12e561b85dabb33903b84e6e Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 21:01:42 +0800 Subject: [PATCH 05/26] try to continue the string without warn. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 57017564657..220e657e21c 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -203,7 +203,8 @@ public void doSubscribe(final URL url, final NotifyListener listener) { listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { if (!child.startsWith("{") && !child.startsWith("[")) { - logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); +// logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); + continue; } child = URL.decode(child); if (!anyServices.contains(child)) { From e215a95a215b48f953af99480d64848f0ef0c49b Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Wed, 8 May 2024 21:04:52 +0800 Subject: [PATCH 06/26] format the code. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 220e657e21c..666f93775d3 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -46,7 +46,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_ERROR_DESERIALIZE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; @@ -203,7 +202,6 @@ public void doSubscribe(final URL url, final NotifyListener listener) { listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { if (!child.startsWith("{") && !child.startsWith("[")) { -// logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", child + "is not json"); continue; } child = URL.decode(child); From 7e1fa5ca285aca774c19639a9f96eecfdc6fd710 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Sat, 11 May 2024 13:56:33 +0800 Subject: [PATCH 07/26] catch the exception of JSONException. --- .../dubbo/registry/zookeeper/ZookeeperRegistry.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 666f93775d3..d828c80de8a 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -42,10 +42,13 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; +import com.alibaba.fastjson2.JSONException; + import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_ERROR_DESERIALIZE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; @@ -201,10 +204,11 @@ public void doSubscribe(final URL url, final NotifyListener listener) { ChildListener zkListener = ConcurrentHashMapUtils.computeIfAbsent( listeners, listener, k -> (parentPath, currentChildren) -> { for (String child : currentChildren) { - if (!child.startsWith("{") && !child.startsWith("[")) { - continue; + try { + child = URL.decode(child); + } catch (JSONException e) { + logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); } - child = URL.decode(child); if (!anyServices.contains(child)) { anyServices.add(child); subscribe( From f991fe2673dcc7df8369ccb27b9b9dbaaa3c0751 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Sat, 11 May 2024 16:37:01 +0800 Subject: [PATCH 08/26] try to fix java.lang.NoClassDefFoundError because of JSONException. --- .../dubbo/registry/zookeeper/ZookeeperRegistry.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index d828c80de8a..5fadaa44390 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -42,7 +42,9 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; -import com.alibaba.fastjson2.JSONException; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY; @@ -206,7 +208,11 @@ public void doSubscribe(final URL url, final NotifyListener listener) { for (String child : currentChildren) { try { child = URL.decode(child); - } catch (JSONException e) { + Object parse = JSON.parse(child); + if (!(parse instanceof JSONObject) && !(parse instanceof JSONArray)) { + throw new Exception(child + "is not json"); + } + } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); } if (!anyServices.contains(child)) { From 2fe1d101eeb8df7edf12da98787b69d44d4ad995 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Thu, 16 May 2024 16:48:50 +0800 Subject: [PATCH 09/26] add isJson method and implement it in JSON. --- .../java/org/apache/dubbo/common/json/JSON.java | 2 ++ .../dubbo/common/json/impl/FastJson2Impl.java | 8 ++++++++ .../apache/dubbo/common/json/impl/FastJsonImpl.java | 10 ++++++++++ .../org/apache/dubbo/common/json/impl/GsonImpl.java | 13 +++++++++++++ .../apache/dubbo/common/json/impl/JacksonImpl.java | 12 ++++++++++++ 5 files changed, 45 insertions(+) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java index 7eddf3d988b..f9da1d2fbc0 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java @@ -23,6 +23,8 @@ public interface JSON { boolean isSupport(); + boolean isJson(String json); + T toJavaObject(String json, Type type); List toJavaList(String json, Class clazz); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJson2Impl.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJson2Impl.java index ef3e783a74e..ed0cca1d81a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJson2Impl.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJson2Impl.java @@ -19,9 +19,17 @@ import java.lang.reflect.Type; import java.util.List; +import com.alibaba.fastjson2.JSONValidator; import com.alibaba.fastjson2.JSONWriter; public class FastJson2Impl extends AbstractJSONImpl { + + @Override + public boolean isJson(String json) { + JSONValidator validator = JSONValidator.from(json); + return validator.validate(); + } + @Override public T toJavaObject(String json, Type type) { return com.alibaba.fastjson2.JSON.parseObject(json, type); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java index 97af77891f3..30d74d47a6f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/FastJsonImpl.java @@ -23,6 +23,16 @@ public class FastJsonImpl extends AbstractJSONImpl { + @Override + public boolean isJson(String json) { + try { + Object obj = com.alibaba.fastjson.JSON.parse(json); + return obj instanceof com.alibaba.fastjson.JSONObject || obj instanceof com.alibaba.fastjson.JSONArray; + } catch (com.alibaba.fastjson.JSONException e) { + return false; + } + } + @Override public T toJavaObject(String json, Type type) { return com.alibaba.fastjson.JSON.parseObject(json, type); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/GsonImpl.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/GsonImpl.java index cd4e53a7ad4..da79d9e91a3 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/GsonImpl.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/GsonImpl.java @@ -20,12 +20,25 @@ import java.util.List; import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; public class GsonImpl extends AbstractJSONImpl { // weak reference of com.google.gson.Gson, prevent throw exception when init private volatile Object gsonCache = null; + @Override + public boolean isJson(String json) { + try { + JsonElement jsonElement = JsonParser.parseString(json); + return jsonElement.isJsonObject() || jsonElement.isJsonArray(); + } catch (JsonSyntaxException e) { + return false; + } + } + @Override public T toJavaObject(String json, Type type) { return getGson().fromJson(json, type); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/JacksonImpl.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/JacksonImpl.java index 28d822f8600..aff91726445 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/JacksonImpl.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/JacksonImpl.java @@ -20,7 +20,9 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; @@ -31,6 +33,16 @@ public class JacksonImpl extends AbstractJSONImpl { private volatile Object jacksonCache = null; + @Override + public boolean isJson(String json) { + try { + JsonNode node = objectMapper.readTree(json); + return node.isObject() || node.isArray(); + } catch (JsonProcessingException e) { + return false; + } + } + @Override public T toJavaObject(String json, Type type) { try { From 0cfde5c05ae3a74efd8a14aa823566d1ced83ca4 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Thu, 16 May 2024 21:23:08 +0800 Subject: [PATCH 10/26] implement the checkJson method and use it in ZookeeperRegistry --- .../main/java/org/apache/dubbo/common/utils/JsonUtils.java | 2 ++ .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java index 0d259c6e51b..b515221b60d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java @@ -146,4 +146,6 @@ public static String getString(Map obj, String key) { public static List checkStringList(List rawList) { return getJson().checkStringList(rawList); } + + public static boolean checkJson(String json) {return getJson().isJson(json);} } diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 5fadaa44390..f22e776ec88 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.CacheableFailbackRegistry; @@ -208,8 +209,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { for (String child : currentChildren) { try { child = URL.decode(child); - Object parse = JSON.parse(child); - if (!(parse instanceof JSONObject) && !(parse instanceof JSONArray)) { + if (!(JsonUtils.checkJson(child))) { throw new Exception(child + "is not json"); } } catch (Exception e) { From 144e8ac9357ed94921cc83d84902bb6990d6f600 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Thu, 16 May 2024 21:27:06 +0800 Subject: [PATCH 11/26] format the code. --- .../main/java/org/apache/dubbo/common/utils/JsonUtils.java | 4 +++- .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java index b515221b60d..3ee05919d4c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java @@ -147,5 +147,7 @@ public static List checkStringList(List rawList) { return getJson().checkStringList(rawList); } - public static boolean checkJson(String json) {return getJson().isJson(json);} + public static boolean checkJson(String json) { + return getJson().isJson(json); + } } diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index f22e776ec88..2164db49981 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -43,10 +43,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONArray; -import com.alibaba.fastjson2.JSONObject; - import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; From 036d2420faa7d2255c3a75175d2a6a2d02209873 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:21:59 +0800 Subject: [PATCH 12/26] add some test case. --- .../dubbo/common/utils/JsonUtilsTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 1b63d217d51..d8db00616bf 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -63,6 +63,53 @@ void teardown() { } } + @Test + void testIsJson() { + JsonUtils.setJson(null); + // prefer use fastjson2 + System.setProperty("dubbo.json-framework.prefer", "fastjson2"); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + System.clearProperty("dubbo.json-framework.prefer"); + + // prefer use fastjson + JsonUtils.setJson(null); + System.setProperty("dubbo.json-framework.prefer", "fastjson"); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + System.clearProperty("dubbo.json-framework.prefer"); + + // prefer use gson + JsonUtils.setJson(null); + System.setProperty("dubbo.json-framework.prefer", "gson"); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + System.clearProperty("dubbo.json-framework.prefer"); + + // prefer use jackson + JsonUtils.setJson(null); + System.setProperty("dubbo.json-framework.prefer", "jackson"); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + System.clearProperty("dubbo.json-framework.prefer"); + } + @Test void testGetJson1() { Assertions.assertNotNull(JsonUtils.getJson()); From 5c5f64a6d4fe1b98e9d648039b7c1dc954cae97d Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:31:35 +0800 Subject: [PATCH 13/26] format the code. --- .../test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index d8db00616bf..4ce692f6e01 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -109,7 +109,6 @@ void testIsJson() { .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } - @Test void testGetJson1() { Assertions.assertNotNull(JsonUtils.getJson()); From 897b9b37b42260aef7c51ef28c6729421afa7696 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:34:44 +0800 Subject: [PATCH 14/26] format the code. --- .../dubbo/common/utils/JsonUtilsTest.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 4ce692f6e01..d194499c3a2 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -68,45 +68,33 @@ void testIsJson() { JsonUtils.setJson(null); // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } @Test From 1b17fa8a5faf4c00e09f0bf3fad9e5aa3130cbe1 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:39:45 +0800 Subject: [PATCH 15/26] format the code. --- .../dubbo/common/utils/JsonUtilsTest.java | 107 +++++++++++------- 1 file changed, 67 insertions(+), 40 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index d194499c3a2..461dcff560b 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -68,35 +68,48 @@ void testIsJson() { JsonUtils.setJson(null); // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } + @Test void testGetJson1() { Assertions.assertNotNull(JsonUtils.getJson()); @@ -104,45 +117,55 @@ void testGetJson1() { Map map = new HashMap<>(); map.put("a", "a"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals( - Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() + .toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson() + .toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() + .toJavaList("[{\"a\":\"a\"}]", Map.class)); // prefer use fastjson2 JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals( - Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() + .toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson() + .toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() + .toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals( - Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() + .toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson() + .toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() + .toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals( - Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() + .toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson() + .toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() + .toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals( - Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() + .toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson() + .toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() + .toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); JsonUtils.setJson(null); @@ -211,28 +234,32 @@ void consistentTest() { JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson2"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - String fromFastjson2 = JsonUtils.getJson().toJson(obj); + String fromFastjson2 = JsonUtils.getJson() + .toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson()); - String fromFastjson1 = JsonUtils.getJson().toJson(obj); + String fromFastjson1 = JsonUtils.getJson() + .toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson()); - String fromGson = JsonUtils.getJson().toJson(obj); + String fromGson = JsonUtils.getJson() + .toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson()); - String fromJackson = JsonUtils.getJson().toJson(obj); + String fromJackson = JsonUtils.getJson() + .toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); JsonUtils.setJson(null); @@ -248,13 +275,13 @@ void consistentTest() { @Test void testGetJson2() { fastjson2Mock = Mockito.mockConstruction(FastJson2Impl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowFastjson2.get())); + .thenAnswer(invocation -> allowFastjson2.get())); fastjsonMock = Mockito.mockConstruction(FastJsonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowFastjson.get())); + .thenAnswer(invocation -> allowFastjson.get())); gsonMock = Mockito.mockConstruction(GsonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowGson.get())); + .thenAnswer(invocation -> allowGson.get())); jacksonMock = Mockito.mockConstruction(JacksonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowJackson.get())); + .thenAnswer(invocation -> allowJackson.get())); // default use fastjson2 JsonUtils.setJson(null); From d19286474ea040b8014a3d84e21635c4df4c78f5 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:43:10 +0800 Subject: [PATCH 16/26] format the code. --- .../dubbo/common/utils/JsonUtilsTest.java | 107 +++++++----------- 1 file changed, 40 insertions(+), 67 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 461dcff560b..d194499c3a2 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -68,48 +68,35 @@ void testIsJson() { JsonUtils.setJson(null); // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } - @Test void testGetJson1() { Assertions.assertNotNull(JsonUtils.getJson()); @@ -117,55 +104,45 @@ void testGetJson1() { Map map = new HashMap<>(); map.put("a", "a"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() - .toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson() - .toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() - .toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals( + Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); // prefer use fastjson2 JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() - .toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson() - .toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() - .toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals( + Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() - .toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson() - .toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() - .toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals( + Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() - .toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson() - .toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() - .toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals( + Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson() - .toJson(map)); - Assertions.assertEquals(map, JsonUtils.getJson() - .toJavaObject("{\"a\":\"a\"}", Map.class)); - Assertions.assertEquals(Collections.singletonList(map), JsonUtils.getJson() - .toJavaList("[{\"a\":\"a\"}]", Map.class)); + Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); + Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); + Assertions.assertEquals( + Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); System.clearProperty("dubbo.json-framework.prefer"); JsonUtils.setJson(null); @@ -234,32 +211,28 @@ void consistentTest() { JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson2"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - String fromFastjson2 = JsonUtils.getJson() - .toJson(obj); + String fromFastjson2 = JsonUtils.getJson().toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson()); - String fromFastjson1 = JsonUtils.getJson() - .toJson(obj); + String fromFastjson1 = JsonUtils.getJson().toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson()); - String fromGson = JsonUtils.getJson() - .toJson(obj); + String fromGson = JsonUtils.getJson().toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson()); - String fromJackson = JsonUtils.getJson() - .toJson(obj); + String fromJackson = JsonUtils.getJson().toJson(obj); System.clearProperty("dubbo.json-framework.prefer"); JsonUtils.setJson(null); @@ -275,13 +248,13 @@ void consistentTest() { @Test void testGetJson2() { fastjson2Mock = Mockito.mockConstruction(FastJson2Impl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowFastjson2.get())); + .thenAnswer(invocation -> allowFastjson2.get())); fastjsonMock = Mockito.mockConstruction(FastJsonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowFastjson.get())); + .thenAnswer(invocation -> allowFastjson.get())); gsonMock = Mockito.mockConstruction(GsonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowGson.get())); + .thenAnswer(invocation -> allowGson.get())); jacksonMock = Mockito.mockConstruction(JacksonImpl.class, (mock, context) -> Mockito.when(mock.isSupport()) - .thenAnswer(invocation -> allowJackson.get())); + .thenAnswer(invocation -> allowJackson.get())); // default use fastjson2 JsonUtils.setJson(null); From 318b95908ea3b5f44e03673cb692c9127ac77a01 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:46:19 +0800 Subject: [PATCH 17/26] format the code. --- .../dubbo/common/utils/JsonUtilsTest.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index d194499c3a2..4ce692f6e01 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -68,33 +68,45 @@ void testIsJson() { JsonUtils.setJson(null); // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertTrue(JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson() + .isJson("This is not a JSON string")); + Assertions.assertTrue(JsonUtils.getJson() + .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } @Test From a33bb105e6b16e31eed85e9169bb1ccd7c0fd78b Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:50:21 +0800 Subject: [PATCH 18/26] format the code. --- .../dubbo/common/utils/JsonUtilsTest.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 4ce692f6e01..27bc143fe56 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -68,45 +68,41 @@ void testIsJson() { JsonUtils.setJson(null); // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); - Assertions.assertFalse(JsonUtils.getJson() - .isJson("This is not a JSON string")); - Assertions.assertTrue(JsonUtils.getJson() - .isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); + Assertions.assertTrue( + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } @Test From 16bc55319cab9b9b835200b9f4678a5e77a7e787 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:53:03 +0800 Subject: [PATCH 19/26] format the code. --- .../org/apache/dubbo/common/utils/JsonUtilsTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 27bc143fe56..b9da1292998 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -69,30 +69,30 @@ void testIsJson() { // prefer use fastjson2 System.setProperty("dubbo.json-framework.prefer", "fastjson2"); Assertions.assertTrue( - JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); Assertions.assertTrue( - JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use fastjson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "fastjson"); Assertions.assertTrue( - JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); Assertions.assertTrue( - JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use gson JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "gson"); Assertions.assertTrue( - JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); Assertions.assertTrue( - JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); // prefer use jackson From 22a7d8b35ec0627548147006e6e76fe072e20ba9 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:53:22 +0800 Subject: [PATCH 20/26] format the code. --- .../java/org/apache/dubbo/common/utils/JsonUtilsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index b9da1292998..7c13d652926 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -99,10 +99,10 @@ void testIsJson() { JsonUtils.setJson(null); System.setProperty("dubbo.json-framework.prefer", "jackson"); Assertions.assertTrue( - JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); + JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}")); Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string")); Assertions.assertTrue( - JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); + JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } @Test From 1b65455d41906a28c4042ddae25d5e2facc83b67 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 18:55:39 +0800 Subject: [PATCH 21/26] format the code. --- .../test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 7c13d652926..4d04e587413 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -105,6 +105,7 @@ void testIsJson() { JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]")); System.clearProperty("dubbo.json-framework.prefer"); } + @Test void testGetJson1() { Assertions.assertNotNull(JsonUtils.getJson()); From 3dcca3a7f0828c83fb5243229225e9a7668fcc08 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 21:52:50 +0800 Subject: [PATCH 22/26] add some information. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 2164db49981..8295dbe13ce 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -206,7 +206,8 @@ public void doSubscribe(final URL url, final NotifyListener listener) { try { child = URL.decode(child); if (!(JsonUtils.checkJson(child))) { - throw new Exception(child + "is not json"); + throw new Exception("decode message failed, beacause " + child + + "is not json,can not be deserialized."); } } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); From 44ea28c118c734d7d4e176d60a23c39f783aa796 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Fri, 17 May 2024 21:55:01 +0800 Subject: [PATCH 23/26] format the code. --- .../org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 8295dbe13ce..56d68071f36 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -207,7 +207,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { child = URL.decode(child); if (!(JsonUtils.checkJson(child))) { throw new Exception("decode message failed, beacause " + child - + "is not json,can not be deserialized."); + + "is not json,can not be deserialized."); } } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); From 7835f393db0955939f46ee142cf1ac818e44399f Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Mon, 20 May 2024 18:43:09 +0800 Subject: [PATCH 24/26] add human friendly comment. --- .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 56d68071f36..5b0e471b97b 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -206,8 +206,9 @@ public void doSubscribe(final URL url, final NotifyListener listener) { try { child = URL.decode(child); if (!(JsonUtils.checkJson(child))) { - throw new Exception("decode message failed, beacause " + child - + "is not json,can not be deserialized."); + throw new Exception( + "dubbo-admin subscribe " + child + " failed,beacause " + child + + "is root path in " + url); } } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); From f5c4bc0824c462734c882984e4c1b1a3d8886d6b Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Mon, 20 May 2024 18:48:59 +0800 Subject: [PATCH 25/26] format the code. --- .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 5b0e471b97b..5a1812b8547 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -206,9 +206,8 @@ public void doSubscribe(final URL url, final NotifyListener listener) { try { child = URL.decode(child); if (!(JsonUtils.checkJson(child))) { - throw new Exception( - "dubbo-admin subscribe " + child + " failed,beacause " + child - + "is root path in " + url); + throw new Exception("dubbo-admin subscribe " + + child + " failed,beacause " + child + "is root path in " + url); } } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage()); From 8012e9f16f5a33de3950be02c65245c006464652 Mon Sep 17 00:00:00 2001 From: walkinggo <40360529+walkinggo@users.noreply.github.com> Date: Mon, 20 May 2024 18:51:48 +0800 Subject: [PATCH 26/26] format the code. --- .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 5a1812b8547..e1eb953d72d 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -206,8 +206,8 @@ public void doSubscribe(final URL url, final NotifyListener listener) { try { child = URL.decode(child); if (!(JsonUtils.checkJson(child))) { - throw new Exception("dubbo-admin subscribe " - + child + " failed,beacause " + child + "is root path in " + url); + throw new Exception("dubbo-admin subscribe " + child + " failed,beacause " + + child + "is root path in " + url); } } catch (Exception e) { logger.warn(PROTOCOL_ERROR_DESERIALIZE, "", "", e.getMessage());