Reputation: 1691
Here is scenario.
I have a JPA entity class with the field
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_DATE", length = 19)
private Date createdDate = null;
And this field is mapped to a column CREATED_DATE with the type datetime
(i am using mysql) in a Table.
When I select
the rows of the table, CREATED_DATE column shows the Date and Time both. When I fetch the row data using query.getSingleResult
and typecast the returned object to the Entity class, the createdDate
field of the entity class also has both Date and Time :
request = (MyEntityClass) query.getSingleResult();<br>
System.out.println(request.getCreatedDate());
prints 2012-05-18 06:32:57.0
in the catalina.out log.
Now I am sending this Entity Class object to a particular client request as a Json object. The Json response the client receives though, when printed, does not show date time, it shows only date:
ClientResponse<String> response = clientRequest.get(String.class);
System.out.println("Response getResource ::"+response.getStatus()+"::"+response.getEntity());
console output:
Response getResource ::200::[{ ....... ,"createdDate":"18-05-2012", ......}]
I am using RestEasy Json api at the server side.
I have seen a similar question ( similar SO post) in SO, but the answer discussed there doesn't seem to work with me.
Please help.
Upvotes: 2
Views: 4521
Reputation: 691805
The problem is related to the way the object is serialized to JSON. You probably configured it in one way or another (annotation, default implementation, config file) so that dates are serialized this way.
Upvotes: 1