Wednesday, February 21, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...