Spring JPA @NotNull和@JsonIgnore

时间:2016-09-01 13:06:30

标签: java spring hibernate bean-validation

如果街道为空,可以做些什么?我将在HTTP POST中获得例外。 NotNull正在检查属性是否为null ...

@NotNull
@Column(name = "street")
@JsonIgnore
private String street;

在这种情况下,JsonIgnore无效。为什么?我想,如果我使用JsonIgnore,那么不会检查null ....

我可以使用@NotNull或其他一些注释来重载@JsonIgnore吗?

1 个答案:

答案 0 :(得分:1)

如果你想"忽略"您可以使用的空值:

redux-form: '^6.0.0-rc.4'

自: How to tell Jackson to ignore a field during serialization if its value is null?

为什么带NotNull的JsonIgnore不起作用?

基本上JSonIgnore注释与Not Null没有关系,因为第一个是Jackson而另一个是JPA。

我相信这些主题可以帮助您:

Serializing JPA entities to JSON using Jackson

Confusion: @NotNull vs @Column(nullable = false)

http://www.davismol.net/2015/03/10/jackson-json-difference-between-jsonignore-and-jsonignoreproperties-annotations/