Write-only properties with Jackson

前端 未结 2 2053
再見小時候
再見小時候 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 02:55

    You can set access value:

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题