htshame
htshame

Reputation: 7330

Validate date (ISO-8601) in request parameters (spring-boot)

In my controller I have:

@RequestMapping(path = "/add", method = POST, produces = "application/json; charset=UTF-8")
public ResponseEntity<Object> saveData(@Valid @RequestBody ReceivedDTO dto)

In ReceivedDTO I have a field:

@JsonProperty("end_date")
@NotNull
private Date endDate;

I need endDate to be in ISO-8601 (e.g. 2007-04-05T14:30Z).

Is it possible to validate the endDate on the DTO level?

Upvotes: 2

Views: 4187

Answers (1)

htshame
htshame

Reputation: 7330

I figured this thing out. All I needed to do is to add @JsonFormat(pattern="yyyy-MM-dd'T'HH:mmX").

Upvotes: 3

Related Questions