Write-only properties with Jackson

前端 未结 2 2070
再見小時候
再見小時候 2021-01-12 02:28

In my entity class, I\'m trying to make a write-only field (gets ignored during serialization, but gets de-serialized normally).

@JsonProperty
@JsonSerialize         


        
2条回答
  •  情深已故
    2021-01-12 03:18

    Use @JsonIgnore on just the getter getPassword, instead of using the NullSerializer. Then also use @JsonProperty("password") on the setter.

    This should allow password to be de-serialized, but the JSON output of serialization won't include it.

    For example, a "getter" method that would otherwise denote a property (like, say, "getValue" to suggest property "value") to serialize, would be ignored and no such property would be output unless another annotation defines alternative method to use.

提交回复
热议问题