I'm joining tables with one to many cardinality, the classes I'm using refer to each other. And I'm using @JsonIgnore annotation with out understanding it deeply.
@JsonIgnore
is used to ignore the logical property used in serialization and deserialization. @JsonIgnore
can be used at setters, getters or fields.
If you add @JsonIgnore
to a field or its getter method, the field is not going to be serialized.
Sample POJO:
class User {
@JsonIgnore
private int id;
private String name;
public int getId() {
return id;
}
@JsonIgnore
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Sample code for serialization:
ObjectMapper mapper = new ObjectMapper();
User user = new User();
user.setId(2);
user.setName("Bob");
System.out.println(mapper.writeValueAsString(user));
Console output:
{"name":"Bob"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With