Skip to content

Instantly share code, notes, and snippets.

@iamvickyav
Last active July 28, 2020 08:06
Show Gist options
  • Save iamvickyav/683d96db6c4d4b4f8fdd08c848b3536e to your computer and use it in GitHub Desktop.
Save iamvickyav/683d96db6c4d4b4f8fdd08c848b3536e to your computer and use it in GitHub Desktop.
// How to ignore fields in Java Object while serializing
// Approach 1 - @JsonIgnoreProperties
@JsonIgnoreProperties(value = {"id", "dob"})
public class User {
private Integer id;
private String name;
private Date dob;
private String city;
// constructors, getters & setters are ignored
}
// Approach 2 - @JsonIgnore
public class User {
@JsonIgnore
private Integer id;
private String name;
@JsonIgnore
private Date dob;
private String city;
// constructors, getters & setters are ignored
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment