- dubbo 3.2.X 以后 支持是否过滤class的开关。
generic.include.class=false
- 如果版本比较低,需要手动过滤掉返回体中的class字段。
/**
* 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");
}
- 使用
JSON.toJSONString(mapString, CLASS_NAME_PRE_FILTER, SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullListAsEmpty)
其中:WriteMapNullValue
保留null字段,WriteNullListAsEmpty
表示把空列表转为[]而不是null。