重命名未在JSON输出中反映的类变量

问题描述 投票:1回答:1

我在Eclipse中使用Spring MVC进行Web服务,从数据库中读取数据并将其转储为JSON。我最近在类中添加了一个新变量,用于从数据库中的表中保存一行,例如:

public class DbRow {
  private Integer Id;
  private String  Label;
  ...
  public String getLabel() {
    return Label;
  }
  public void setLabel(String label) {
    this.Label = label;
  }
}

但是,随着后来数据库中列的名称发生变化,我通过重命名类变量(在Eclipse中使用Refactor - > Rename ...或Alt + Shift + R)以及像这样的getter和setter方法来反映这一点。 :

public class DbRow {
  private Integer Id;
  private String  Title;
  ...
  public String getTitle() {
    return Title;
  }
  public void setLabel(String title) {
    this.Title = title;
  }
}

现在我的问题是,在服务的JSON输出中,字段仍然是这样的旧名称

{"Id":"100","Label":"Test"}

代替

{"Id":"100","Title":"Test"}

这打破了我在Eclipse中使用TestNG运行的mockMvc测试(例如错误org.springframework.restdocs.snippet.SnippetException:在有效负载中找不到具有以下路径的字段:[Title])。

我怎么能解决这个问题?

java json spring eclipse spring-mvc
1个回答
0
投票

你的setter方法仍旧

public void setLabel(String title) { this.Title = title; }

setTitle(String title)更新它。此外,尝试清理构建项目并在之后运行测试用例。

© www.soinside.com 2019 - 2024. All rights reserved.