LoginSignup
0
0

More than 1 year has passed since last update.

【Java】アノテーション

Posted at

@￰JsonProperty

  • Javaインスタンスのシリアライズ時のプロパティ名を指定する

@￰JsonIgnore

  • Jsonに含めたくないプロパティを指定する

サンプルコード

Javaクラス

User.java
package annotations.naming;

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

public class User {
  private Long id;

  @JsonProperty("firstName")
  private String name;

  @JsonIgnore
  private String password;

  public Long getId() {
    return this.id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getName() {
    return this.name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getPassword() {
    return this.password;
  }

  public void setPassword(String password) {
    this.password = password;
  }
}

Json

{
  "id" : 1,
  "firstName" : "Tom"
}
0
0
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
0