From e3017394dd216768b3547d6f747a4d035dbfba92 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Wed, 7 Oct 2020 13:55:08 +0300 Subject: [PATCH] Re-define Book publish attribute JSON read/write policy Signed-off-by: Pekka Helenius --- .../com/fjordtek/bookstore/model/book/Book.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/Book.java index 127f35b..c1ac1ca 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/Book.java @@ -30,6 +30,8 @@ import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty.Access; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fjordtek.bookstore.annotation.CurrentYear; @@ -239,7 +241,16 @@ public class Book { nullable = false, columnDefinition = "BIT" ) - @JsonIgnore + /* + * We allow writing this attribute value as JSON data (POST/PUT requests) + * while ignore outputting it in JSON output (GET requests) + * + * Basic scenario: allow updating via REST API while preventing to access + * it, for instance, when requesting book JSON data for reading. + */ + @JsonProperty( + access = Access.WRITE_ONLY + ) private boolean publish; ////////////////////