Reputation: 123
What can be done, if street is null? I will get an exception in the HTTP POST
. NotNull is checking if property is null or not...
@NotNull
@Column(name = "street")
@JsonIgnore
private String street;
In this case JsonIgnore
is not working. Why? I thought, if I use JsonIgnore
not null would not be checked....
Can I overload @NotNull
with @JsonIgnore
or some other annotation?
Upvotes: 3
Views: 4192
Reputation: 770
If you want to "ignore" null values you can use:
@JsonInclude(Include.NON_NULL)
class Foo
{
String bar;
}
from: How to tell Jackson to ignore a field during serialization if its value is null?
Why JsonIgnore with NotNull doesnt work?
Basically the JSonIgnore annotation has not relationship with Not Null because the first is Jackson and the other is JPA.
I believe these topics can help you:
Serializing JPA entities to JSON using Jackson
Confusion: @NotNull vs @Column(nullable = false)
Upvotes: 1