在我向POJO添加新字段后,为什么JSON没有更改

问题描述

我向POJO添加了新字段,希望在Spring Boot应用程序中找到它们作为响应。这是带有Lombok批注的简单POJO:

@Getter
@Setter
@NoArgsConstructor
public class Responce implements AsyncResponse,Serializable {
    private String resultCode;
    private String errorCode; // added field

public Responce(String resultCode) {
    this.resultCode = resultCode;
    }
}

在我的服务方法中,我创建了对象,然后使用设置器添加了额外的字段errorCode:

Responce response = new Responce("0");
responce.setErrorCode("777");

但是我仍然收到带有一个字段的JSON:

{
    resultCode: "0"
}

如何强制包含新字段?

UPD: AsyncResponse看起来像这样

public interface AsyncResponse {
    String getResultCode();
    void setResultCode(String resultCode);

    String getErrorCode(); // added getter
    void setErrorCode(String errorCode); // added setter
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)