Use @JsonView to exclude (like @JsonIgnore) with play frameworks default json writer?

后端 未结 2 412
Happy的楠姐
Happy的楠姐 2021-01-24 03:16

It seems you can\'t mix @JsonIgnore and @JsonView. I want to hide a field by default, but show it in some cases.

Basically I\'ve got this setup :-

class         


        
2条回答
  •  日久生厌
    2021-01-24 04:09

    Once you have an object mapper, you can effectively use it in the same way as you are currently using play.libs.Json.toJson(parent), and get exactly what you want.

    So whenever you were previously using play.libs.Json.toJson(parent), just use new ObjectMapper().writeValueAsString() and you won't get your secret.

提交回复
热议问题