You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "farliu (GitHub)" <gi...@apache.org> on 2019/08/18 02:36:58 UTC

[GitHub] [dubbo] farliu opened issue #4863: 泛化调用,返回值增加的class字段,增加开关。

- [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [ ] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.6.0
* Operating System version: centos
* Java version: 1.8

### 需求
泛化调用,返回值增加的class字段,增加开关。

### 举例
在PojoUtils.java中,有两处应该怎么增加该开关,如下:
1. put "class" 字段
```
Map<String, Object> map = new HashMap<String, Object>();
history.put(pojo, map);
map.put("class", pojo.getClass().getName());
```

2. 根据条件remove "class" 字段
```
// when return type is not the subclass of return type from the signature and not an interface
if (!type.isInterface() && !type.isAssignableFrom(pojo.getClass())) {
    try {
        map = (Map<Object, Object>) type.newInstance();
        Map<Object, Object> mapPojo = (Map<Object, Object>) pojo;
        map.putAll(mapPojo);
        map.remove("class");
    } catch (Exception e) {
        //ignore error
        map = (Map<Object, Object>) pojo;
    }
} else {
    map = (Map<Object, Object>) pojo;
}
```

应该修改成:
1. put "class" 字段
```
Map<String, Object> map = new HashMap<String, Object>();
history.put(pojo, map);
if (keepGenericClass){  // to increase the switch for control generics
    map.put("class", pojo.getClass().getName());
}
```

2. 根据条件remove "class" 字段
```
// when return type is not the subclass of return type from the signature and not an interface
if (!type.isInterface() && !type.isAssignableFrom(pojo.getClass())) {
    try {
        map = (Map<Object, Object>) type.newInstance();
        Map<Object, Object> mapPojo = (Map<Object, Object>) pojo;
        map.putAll(mapPojo);
            if (keepGenericClass){  // to increase the switch for control generics
                map.remove("class");
            }
    } catch (Exception e) {
        //ignore error
        map = (Map<Object, Object>) pojo;
    }
} else {
    map = (Map<Object, Object>) pojo;
}
```


[ Full content available at: https://github.com/apache/dubbo/issues/4863 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [dubbo] farliu commented on issue #4863: 泛化调用,返回值增加的class字段,建议增加开关。

Posted by "farliu (GitHub)" <gi...@apache.org>.
> I just add this code to my generic invoke application to return json

the problem is solved with your code, but it is still recommended to add a switch.

[ Full content available at: https://github.com/apache/dubbo/issues/4863 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [dubbo] qixiaobo commented on issue #4863: 泛化调用,返回值增加的class字段,建议增加开关。

Posted by "qixiaobo (GitHub)" <gi...@apache.org>.
I just add this code to my generic invoke application to return json 

[ Full content available at: https://github.com/apache/dubbo/issues/4863 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [dubbo] chickenlj closed issue #4863: 泛化调用,返回值增加的class字段,建议增加开关。

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
[ issue closed by chickenlj ]

[ Full content available at: https://github.com/apache/dubbo/issues/4863 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org