PUT and POST fail on unknown properties Spring different behavior

前端 未结 4 1573
野的像风
野的像风 2021-01-07 19:46

I am writing Spring Boot application using Spring Data Rest repositories and I want to deny access to resource if request body contains JSON that has unknown properties. Def

4条回答
  •  天命终不由人
    2021-01-07 20:37

    you can annotate your model with :

    @Entity
    @JsonIgnoreProperties(ignoreUnknown=false)
    public class Person{
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long id;
    
        private String firstName;
        private String lastName;
    
        /* getters and setters */
    }
    

提交回复
热议问题