说我有这个JSON

{
  "propertA" : "test"
}


使用此类将反序列化为对象

public static class MyClass
{
  private String propertya;

  @JsonGetter( "propertya" )
  public String getPropertya() { return this.propertya; }

  @JsonSetter( "propertyA" )
  public void setPropertya( String a ){ this.propertya = a };
}


我使用@JsonGetter,因此可以将该对象实例序列化为以下内容:

{
  "properta" : "test"
}


但是没有,我仍然得到以下信息:

{
  "propertA" : "test"
}


我究竟做错了什么?我期望@JsonGetter将我的类实例属性“ propertya”序列化为“ propertya”,但是@JsonSetter似乎在序列化时接管了该控件。 @JsonGetter到底是做什么的?看起来并没有影响对象的序列化方式。

最佳答案

我更新到版本2.4.0,并且可以正常工作。但是我必须将@JsonIgnore添加到字段中,这很好。

在2.4.0中,以下代码应该可以工作:

public static class MyClass
{
  @JsonIgnore
  private String propertya;

  @JsonGetter( "propertya" )
  public String getPropertya() { return this.propertya; }

  @JsonSetter( "propertyA" )
  public void setPropertya( String a ){ this.propertya = a };
}

07-24 02:01