gpt4 book ai didi

java - 重命名通用类中的元素名称

转载 作者:行者123 更新时间:2023-12-01 06:07:34 24 4
gpt4 key购买 nike

我正在使用 Jackson,并且我正在使用通用类来进行如下响应:

public class GenericListInfoResponse<T> extends GenericResponse {

private T resultInfo;

public GenericListInfoResponse(T resultInfo) {
super();
this.resultInfo = resultInfo;
}

public T getResultInfo() {
return resultInfo;
}

public void setResultInfo(T resultInfo) {
this.resultInfo = resultInfo;
}

}

我设置了一些来 self 的服务的数据:

TitleListInfo titleListInfo = dropdownDataService.getTitleList(transactionId);
response.setResultInfo(titleListInfo);

之后返回的是这样的JSON:

{
"resultInfo": {
"combinedMessage": "",
"messageCode": null
...
}

我想重命名元素名称而不是“resultInfo”。例如“标题信息”

最佳答案

我猜你想在不改变变量名称的情况下做到这一点?尝试使用 @JsonProperty("titleInfo") 注释字段,它应该可以工作。

@JsonProperty("titleInfo")
private T resultInfo;

如果不起作用,请尝试注释 getter 和 setter。

关于java - 重命名通用类中的元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com