2

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

enter image description here

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
  }
 ]
}
Balaji
  • 191
  • 3
  • 14
  • Are you sure the problem is at the backend? Is the client which sends the json request object to the London server the same as the one that sends it to the NY server? Can you verify that the date in the request object is the one above in both cases? Maybe the request object itself is already invalid... – JanTheGun Jul 25 '16 at 09:45
  • @JanTheGun I ran the test against POSTMAN - a rest client. And not from the UI. Same request was tested against my local endpoint and against the New york server endpoint. My gut feeling is that the value when being parsed is wrong. And also please have a look at the match data returned from New york server. The date in the response is completely different from the input object – Balaji Jul 25 '16 at 11:19
  • 1
    If you have Java 8 at your hands, you may try the support for the new date and time types in https://github.com/FasterXML/jackson-datatype-jsr310 as this answer states http://stackoverflow.com/a/27952529/799562 – micfra Jul 25 '16 at 11:37
  • It is weird that it is exactly one day before the requested date. Just thinking loud: Maybe there is an issue with the time... 2016-11-30 24:00 = 2016-12-01 00:00 – JanTheGun Jul 25 '16 at 11:38
  • @JanTheGun my apologies to have missed out on the service code which is being used instead of the actual query. I query a table called "CcarReport" which has one to many relationship to "CcarReportWfInstances" which contains the date attribute. Please look at the updated post. let me know if you require additional information – Balaji Jul 25 '16 at 11:45

0 Answers0