【发布时间】:2021-01-12 00:03:56
【问题描述】:
我已经向 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;
}
}
在我的服务方法中,我创建了对象,然后使用 setter 来添加额外的字段 errorCode:
Responce response = new Responce("0");
responce.setErrorCode("777");
但我仍然收到一个包含一个字段的 JSON:
{
resultCode: "0"
}
如何强制包含新字段?
更新: AsyncResponse 看起来像这样
public interface AsyncResponse {
String getResultCode();
void setResultCode(String resultCode);
String getErrorCode(); // added getter
void setErrorCode(String errorCode); // added setter
}
【问题讨论】:
-
你能展示这个
AsyncResponse类吗?或Responce和AsyncResponse上使用的所有杰克逊注解 -
您是否尝试过清理并重新构建。 ?或尝试除
errorCode之外的其他方法 -
你用的是spring boot的嵌入式tomcat?能否验证一下编译时生成的war包是否更新了?
-
@Deadpool 在 POJO 中除了提到的类级别上没有注释。 AsyncResponce 中也没有注释。
-
@abs_dev 它是一个 tomcat,真的。我们在交付管道中使用 Jenkins,所以据我所知,是的 jar 已更新。
标签: java json spring-boot jackson lombok