LoginSignup
0
2

More than 5 years have passed since last update.

[Java][Jackson] JSONシリアライズするけど、デシリアライズしないプロパティを定義するtips

Posted at

フィールドに@JsonIgnoreアノテーションを付けます。
ゲッターに@JsonPropertyアノテーションを付けます。
セッターに@JsonIgnoreアノテーションを付けます。

以下サンプルです。

SampleEntity.java
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

public class SampleEntity implements Serializable {

    @JsonIgnore
    private Integer myId;

    @JsonProperty("myId")
    public Integer getMyId() { /* 省略 */ }

    @JsonIgnore
    public void setMyId(Integer myId) { /* 省略 */ }
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2