Wednesday, 16 May 2018

json - Convert java.util.Date to java.sql.Date with 'yyyy-mm-dd hh mm ss'

I need to pass json string to one of the rest web service. There is a property called 'amortizationdate' which will have format 'yyyy-mm-dd hh mm ss'.




for e.g. {amortizationdate:2015-07-31 00:00:00}



we are having AmortizationVO.java with a property amortizationdate.



for e.g



private java.sql.Date amortizationDate.

public void setAmortizationDate(java.sql.Date date){


}


We need to set the date by calling setAmortizationDate(..date) method and using Jackson to convert AmortizationVO.java to Json.



but in JSON I m getting {amortizationdate:2015-07-31}. But expected result should be with timestamp.(amortizationdate:2015-07-31 00:00:00)



note: I don't want to use util date in my Value Object.



Pls help.




What I've tried:



java.util.Date utilDate = new java.util.Date();
java.sql.Timestamp sq = new java.sql.Timestamp(utilDate.getTime());


ExcelEntityAddressVO entityAddressVO = new ExcelEntityAddressVO();
entityAddressVO.setAmortizationDate(new java.sql.Date(sq.getTime()));



This is my JSON:



{
"amortizationdate" : "2015-07-31",
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...