You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
SOP/doc/docs/files/10099_更改数据节点名称.md

1.3 KiB

更改数据节点名称

针对alipay.story.find接口,它的返回结果如下:

{
	"alipay_story_find_response": {
		"msg": "Success",
		"code": "10000",
		"name": "白雪公主",
		"id": 1,
		"gmtCreate": 1554193987378
	},
	"sign": "xxxxx"
}

其中alipay_story_find_response是它的数据节点。规则是:

将接口名中的"."转换成"_",后面加上"_response"。

代码实现如下:

String method = "alipay.story.find";
return method.replace('.', '_') + "_response";

详见DefaultDataNameBuilder.java

如果要更改数据节点,比如result,可使用CustomDataNameBuilder.java

@Configuration
public class ZuulConfig extends AlipayZuulConfiguration {

    static {
        ...
        ApiConfig.getInstance().setDataNameBuilder(new CustomDataNameBuilder());
        ...
    }

}

设置后,网关统一的返回结果如下:

{
	"result": {
		...
	},
	"sign": "xxxxx"
}

此外,构造方法可指定自定义字段名称:new CustomDataNameBuilder("data");。 设置后,数据节点将变成data

{
	"data": {
		...
	},
	"sign": "xxxxx"
}

:网关设置了CustomDataNameBuilder后,SDK也要做相应的更改:SdkConfig.dataNameBuilder = new CustomDataNameBuilder();