You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/11 12:25:57 UTC

[dubbo] branch master updated: [Dubbo-4863] add switch of generic invocation with class info (#5412)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b03c3f  [Dubbo-4863] add switch of generic invocation with class info (#5412)
3b03c3f is described below

commit 3b03c3f29807b654b12af5376ecedd494be12acb
Author: GuoHao <gu...@gmail.com>
AuthorDate: Wed Dec 11 20:25:46 2019 +0800

    [Dubbo-4863] add switch of generic invocation with class info (#5412)
    
    fix #4863
---
 .../org/apache/dubbo/common/constants/CommonConstants.java     |  2 ++
 .../src/main/java/org/apache/dubbo/common/utils/PojoUtils.java | 10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index 1dd81ed..0d9f9ce 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -262,6 +262,8 @@ public interface CommonConstants {
 
     String GENERIC_SERIALIZATION_PROTOBUF = "protobuf-json";
 
+    String GENERIC_WITH_CLZ_KEY = "generic.include.class";
+
     /**
      * The limit of callback service instances for one interface on every client
      */
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
index 0b1a3a8..c46fcbc 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.common.utils;
 
+import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 
@@ -64,6 +65,7 @@ public class PojoUtils {
     private static final Logger logger = LoggerFactory.getLogger(PojoUtils.class);
     private static final ConcurrentMap<String, Method> NAME_METHODS_CACHE = new ConcurrentHashMap<String, Method>();
     private static final ConcurrentMap<Class<?>, ConcurrentMap<String, Field>> CLASS_FIELD_CACHE = new ConcurrentHashMap<Class<?>, ConcurrentMap<String, Field>>();
+    private static final boolean GENERIC_WITH_CLZ = Boolean.parseBoolean(ConfigUtils.getProperty(CommonConstants.GENERIC_WITH_CLZ_KEY,"true"));
 
     public static Object[] generalize(Object[] objs) {
         Object[] dests = new Object[objs.length];
@@ -164,7 +166,9 @@ public class PojoUtils {
         }
         Map<String, Object> map = new HashMap<String, Object>();
         history.put(pojo, map);
-        map.put("class", pojo.getClass().getName());
+        if (GENERIC_WITH_CLZ) {
+            map.put("class", pojo.getClass().getName());
+        }
         for (Method method : pojo.getClass().getMethods()) {
             if (ReflectUtils.isBeanPropertyReadMethod(method)) {
                 try {
@@ -401,7 +405,9 @@ public class PojoUtils {
                     map = (Map<Object, Object>) type.newInstance();
                     Map<Object, Object> mapPojo = (Map<Object, Object>) pojo;
                     map.putAll(mapPojo);
-                    map.remove("class");
+                    if (GENERIC_WITH_CLZ) {
+                        map.remove("class");
+                    }
                 } catch (Exception e) {
                     //ignore error
                     map = (Map<Object, Object>) pojo;