I have a model where I need to accept only dates with the format "dd/MM/yyyy. For that I am using jackson JsonFormat
.
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
import java.util.UUID;
@Data
@AllArgsConstructor(onConstructor = @__(@JsonCreator))
public class InventoryVolume {
private UUID itemID;
@JsonFormat(pattern = "dd/MM/yyyy")
public Date inventoryStartDate;
private UUID ItemSpecID;
}
Now I expect dates with format dd/MM/yyyy
(max length 10) only to be accepted and rest all to throw an exception.
But looks like the only thing that is checked is "/" between dates.
All of these following formats are deserialized and converted to valid date!! Is this an expected behavior?
Year
"inventoryStartDate": "01/01/11ff"
"inventoryStartDate": "01/01/11fff"
"inventoryStartDate": "01/01/1111111111"
"inventoryStartDate": "01/01/11"
Month
"inventoryStartDate": "01/35/11"
Date
"inventoryStartDate": "023466234/12/11"