I'm trying to exclude the possibility of a json field to be modificated at HTTP.POST operation. This is my class:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserModel {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long userId;
@NotNull
private String username;
private RoleModel role;
@NotNull
private String email;
@NotNull
private String firstName;
@NotNull
private String secondName;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private String password;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date registrationDate;
}
I want for example the property userId to be accessible only for read (http get). I've tried with @JsonProperty but it doesn't work, instead it works for the password field. (this property is visible only for write/ post).
Can you please tell me where I'm wrong? or if there is a more elegant way to do that?
Many thanks,