英文:
Why did not JSON change after I added new fields to POJO
问题
我已经在我的Spring Boot应用程序中的POJO中添加了新的字段,希望在响应中找到它们。这是一个带有Lombok注释的简单POJO:
@Getter
@Setter
@NoArgsConstructor
public class Response implements AsyncResponse, Serializable {
private String resultCode;
private String errorCode; // 新添加的字段
public Response(String resultCode) {
this.resultCode = resultCode;
}
}
在我的服务方法中,我创建了一个对象,然后使用setter方法添加了额外的字段errorCode:
Response response = new Response("0");
response.setErrorCode("777");
但是我仍然收到只有一个字段的JSON响应:
{
"resultCode": "0"
}
我如何强制包含新添加的字段?
更新:
AsyncResponse看起来是这样的:
public interface AsyncResponse {
String getResultCode();
void setResultCode(String resultCode);
String getErrorCode(); // 新添加的getter
void setErrorCode(String errorCode); // 新添加的setter
}
英文:
I have added new fields to POJO expecting to find them in response in my Spring Boot application. It is a simple POJO with Lombok annotations:
@Getter
@Setter
@NoArgsConstructor
public class Responce implements AsyncResponse, Serializable {
private String resultCode;
private String errorCode; // added field
public Responce(String resultCode) {
this.resultCode = resultCode;
}
}
In my service method I have created object and then used a setter for added extra field errorCode:
Responce response = new Responce("0");
responce.setErrorCode("777");
But I still receive a JSON with one field:
{
resultCode: "0"
}
How I can force to include new field?
UPD:
AsyncResponse looks like this
public interface AsyncResponse {
String getResultCode();
void setResultCode(String resultCode);
String getErrorCode(); // added getter
void setErrorCode(String errorCode); // added setter
}
答案1
得分: 0
在网关模块的application.yml中设置了一个过滤器,其中在fieldsToRetain参数中没有提及字段。
英文:
There was a filter set up in application.yml in gateway module which hadn't mentioned fields in fieldsToRetain parameter.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论