Dubbo: 求一套去掉dubbo泛化返回的class的算法(多层结构嵌套)

Created on 2 Jul 2020  ·  14Comments  ·  Source: apache/dubbo

求一套去掉dubbo泛化返回的class的算法(多层结构嵌套),目前我只去掉了外层,里边的没去掉
{ "code": 200, "msg": "访问成功!", "rlt": { "msg": "en", "rlt": { "name": "en", "id": "123", "class": "org.dromara.soul.test.dubbo.api.entity.DubboTest" }, "statusCode": 200 } }

typquestion & discussion

Most helpful comment

2.7.6 with issue #4863
In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

👍
这是在dubbo哪个类里啊 我2.7.6和2.7.8都没找到啊,求告知

2.7.6 supports the switch.
You can turn off it with 'generic.include.class=false'
This code above just for the low dubbo version

这个开关是在服务提供方设置的,但是网关泛化调用,是不是最好在消费端控制会好

All 14 comments

不可以自己做个迭代吗?dubbo返回的都是嵌套的map, map里面只要找到的名称为class, 就remove掉好了

不可以自己做个迭代吗?dubbo返回的都是嵌套的map, map里面只要找到的名称为class, 就remove掉好了

就是想弄个最优的,看看大家有没有遇到过的,并且找到比较好的方法了,求开源

还是求一个算法,因为我发现光map还好处理,但是还list中有对象等等

之前也有这个困惑,不过还是自己写了套逻辑去去掉了class,最好框架有开关可以选择去掉

之前也有这个困惑,不过还是自己写了套逻辑去去掉了class,最好框架有开关可以选择去掉

恩,我认为应该框架直接去掉最好,目前我保证了map和集合去掉class了,您的算法方便分享一下吗

这个之前不是有人改过了吗,加了个开关,不知道你使用的是哪个版本,可以看下PojoUtils中是否含有GENERIC_WITH_CLZ这个字段。

这个之前不是有人改过了吗,加了个开关,不知道你使用的是哪个版本,可以看下PojoUtils中是否含有GENERIC_WITH_CLZ这个字段。

我去看一眼,谢谢

这个之前不是有人改过了吗,加了个开关,不知道你使用的是哪个版本,可以看下PojoUtils中是否含有GENERIC_WITH_CLZ这个字段。

能说一下改过的是哪个版本吗,非常感谢。我的项目没找到,百度搜也没有。

这个之前不是有人改过了吗,加了个开关,不知道你使用的是哪个版本,可以看下PojoUtils中是否含有GENERIC_WITH_CLZ这个字段。

能说一下改过的是哪个版本吗,非常感谢。我的项目没找到,百度搜也没有。

2.7.5吧,,记不清了,对应的issue是#5412

2.7.6 with issue https://github.com/apache/dubbo/issues/4863

In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

2.7.6 with issue #4863

In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

👍

2.7.6 with issue #4863
In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

👍
这是在dubbo哪个类里啊 我2.7.6和2.7.8都没找到啊,求告知

2.7.6 with issue #4863
In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

👍
这是在dubbo哪个类里啊 我2.7.6和2.7.8都没找到啊,求告知

2.7.6 supports the switch.
You can turn off it with 'generic.include.class=false'
This code above just for the low dubbo version

2.7.6 with issue #4863
In my project,I just use a fastjson filter to instead of upgrading dubbo version
I think you just want output json to frontend

/**
     * remove specify class field refer to dubbo generic invoke
     */
    private static final SimplePropertyPreFilter CLASS_NAME_PRE_FILTER = new SimplePropertyPreFilter(HashMap.class);

    static {
        CLASS_NAME_PRE_FILTER.getExcludes().add("class");
    }

When I output my json , I use this code below

JSON.toJSONString(result, CLASS_NAME_PRE_FILTER), CharsetUtil.UTF_8)

👍
这是在dubbo哪个类里啊 我2.7.6和2.7.8都没找到啊,求告知

2.7.6 supports the switch.
You can turn off it with 'generic.include.class=false'
This code above just for the low dubbo version

这个开关是在服务提供方设置的,但是网关泛化调用,是不是最好在消费端控制会好

Was this page helpful?
0 / 5 - 0 ratings