0

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",
}
cнŝdk
  • 30,215
  • 7
  • 54
  • 72
user2057006
  • 577
  • 3
  • 13
  • 27

2 Answers2

1

You don't want java.sql.Date - it doesn't keep time, use java.sql.Timestamp

user158037
  • 2,582
  • 1
  • 22
  • 26
0

You can try this:

import java.sql.Timestamp;

public class Test {

       public static void main(String[] args) {
            java.util.Date utilDate = new java.util.Date();
            System.out.println("utilDate:" + utilDate);
            Timestamp ts = new Timestamp(utilDate.getTime());
            System.out.println(ts);
       }
}
Kenny Tai Huynh
  • 1,366
  • 10
  • 21