How to take Date time as a input in request body of a post mapping controller.
This is my controller which is taking request body of a object DTO.
@PostMapping(value = "/filterJobs")
@ResponseStatus(HttpStatus.OK)
public ApiResponse getFilteredJobs(@RequestParam(defaultValue = "0") Integer pageNo,
@RequestParam(defaultValue = "20") Integer pageSize,
@RequestBody FilteredJobsDto filteredJobsDto) {
Code here but its coming even to the first line of code
}
I am taking FilteredJobsDto in request body which has following parameters
public class FilteredJobsDto implements Serializable {
private String jobName;
private Long createdBy;
private String status = "submitted";
private String tenantId;
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
@JsonDeserialize(using = DateTimeDeserializer.class)
private DateTime startDate;
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private DateTime endDate;
}
My json body looks like this as of now:
{
"jobName": "email notification",
"startDate": "2023-03-02T08:20:11.000Z",
"status": "submitted"
}
The error i am facing here is a bad request in postman and on the console side :
logException : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 3 column 19 path $.startDate; nested exception is com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 3 column 19 path $.startDate]
When i am not taking startDate in json body, the api is working fine, but as soon as i put "startDate": "2023-03-02T08:20:11.000Z" this in my json body, it throws an error.
Can someone please help me resolve this!