DateTimeFormat accepting numbers in json request instead of date format

hacker :

I need to validate date using jsr annotations / spring rest

@Email(regexp = ".+@.+\\..+")
private String email;
@NotNull
@JsonFormat(pattern="yyyy-MM-dd")
private LocalDate dateOfBirth;

But its accepting below json request

{ "email": "[email protected]","dateOfBirth": 7,}

and its parsing the date as 1970-01-07 (adding 7 days from 1970)

even below annotation is allowing numbers

 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")

How can I invalidate this request

hacker :

Ended up writing my own deserializer

class LocalDateDeserializer extends StdDeserializer<LocalDate> {

protected LocalDateDeserializer(){
    super(LocalDate.class);
}

@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    return LocalDate.parse(jp.readValueAs(String.class));

}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=160022&siteId=1