1

I'have a spring-boot rest microservice, I need to validate object if the request has no extra fields.

My dto request class:

public class Request implements Serializable {
 @NotNull(message = "{validation.field.notNull}")
 private String field1;
 @NotNull(message = "{validation.field.notNull}")
 private String field2;

/* getter and setter*/
} 

I want to thorw the MethodArgumentNotValidException if the request contains extra field like this: POST request:

{
 field1 "val1",
 field2: "val2",
 field3: "val3" --error
}

Thanks

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
raffaeleambrosio
  • 235
  • 2
  • 11
  • 1
    Possible duplicate of [Spring Boot 1.4 Customize Internal Jackson Deserialization](https://stackoverflow.com/questions/42874369/spring-boot-1-4-customize-internal-jackson-deserialization) – Alan Hay Nov 30 '18 at 11:44
  • The linked question has answers that should be usable in both spring boot and non spring-boot contexts. – Alan Hay Nov 30 '18 at 11:45

0 Answers0