All,
I have a column in database which captures and stores the dates in "yyyy-MM-DD" format. Data coming from UI is a JSON. I have used Jackson mapper to parse the date as follows ( attribute is cobDate)
I used sprint boot stack in my application. Screenshot from my database as to how its stored
Service code through which I do a match. I have used apache supplied date comparison here which ignores the time .In the search parameter , I have report Id which is the parent class and has one to many to the entity that holds the date attibute(Entity name CcarReportWorkflowInstance - I fetch this list using parent.getter())
@Transactional
public CcarResponseDTO fetchWfDetails(Long reportId, Date cobDate) {
CcarResponseDTO ccarResponseDTO = new CcarResponseDTO();
try {
CcarReport ccarReport = validateInstSearchParams(reportId, cobDate);
List<CcarReportWorkflowInstance> filteredRepInstList = StreamSupport.stream(ccarReport.getCcarReportWorkflowInstances())
.filter(ccarRepWfInst -> DateUtils.isSameDay(cobDate, ccarRepWfInst.getCobDate()))
.collect(java8.util.stream.Collectors.toList());
log.info("Filtered workflow instance list size =" + filteredRepInstList.size());
List<CcarRepWfInstDTO> ccarRepWfInstDTOs = ccarRepWfInstMapper.ccarRepWfInstsToCcarRepWfInstDTOs(filteredRepInstList);
ccarResponseDTO.setWorkflowInstList(ccarRepWfInstDTOs);
} catch (Exception e) {
log.error("Exception while fetch workflow instances =" + e);
throw new CustomParameterizedException(e.getMessage());
}
return ccarResponseDTO;
}
DTO object which is going to parse the incoming JSON
public class CcarRepWfInstDTO implements Serializable {
private Long id;
private Long reportId;
private Long workflowInstanceId;
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")
private Date cobDate;
private String frequency;
private String runType;
private String reportVersion;
private String workflowStatus;
}
When my local machine ( machine based out of london time zone ) , everything works as expected.Response for the same request running in DEV server ( newyork based one). I am not sure how and whats going wrong. Why Jackson is behaving wierd. Have I missed something.Below is the code of the entity that is going to persist the column.
@Column(name = "COB_DATE", nullable = false)
@Temporal(TemporalType.DATE)
private Date cobDate;
I have a rest service that will return me the list of entities based on date search criteria which is working fine in my local. Request object,search results are as follows
{
"reportId":"1050",
"cobDate":"2016-12-01"
}
Response from locally deployed server running in London
{ "workflowInstList": [
{
"id": 9050,
"reportId": 1050,
"workflowInstanceId": 1833698,
"cobDate": "2016-12-01",
"frequency": "Daily",
"runType": "Fed Submission",
"reportVersion": "2.4",
"workflowStatus": null
},
{
"id": 9850,
"reportId": 1050,
"workflowInstanceId": 1835204,
"cobDate": "2016-12-01",
"frequency": "Daily",
"runType": "Fed Submission",
"reportVersion": "2.4",
"workflowStatus": null
},
{
"id": 9350,
"reportId": 1050,
"workflowInstanceId": 1834019,
"cobDate": "2016-12-01",
"frequency": "Daily",
"runType": "Fed Submission",
"reportVersion": "2.4",
"workflowStatus": null
}
]
}
Response from NY machine
{ "workflowInstList": [
{
"id": 10600,
"reportId": 1050,
"workflowInstanceId": 1854803,
"cobDate": "2016-11-30",
"frequency": "Daily",
"runType": "Fed Submission",
"reportVersion": "2.4",
"workflowStatus": null
}
]
}