反序列化和使用Lombok时忽略JSON属性

时间:2019-10-25 17:37:33

标签: java json

我有一个使用lombok的模型类,如下所示。我想序列化这两个字段以供用户输入到Json,并且当用户对象反序列化并返回到前端时,我希望“ id”字段不包含在响应中。我尝试使用@JsonIgnoreProperties allowGetters = true,但随后似乎“ id”字段未在输入中序列化,请求中的ID为null。我是否误解了allowGetters的使用?谢谢。

@Data
@JsonIgnoreProperties(value={ "id" }, allowGetters=true)
public class User implements Serializable {

  private Integer id;  
  private String name;
}

0 个答案:

没有答案