I created a RESTful web service using JAX-RS annotations:
@GET @Path("/test") @Produces(MediaType.APPLICATION_JSON) public MyThing test() { MyThing myObject = new MyThing(LocalDateTime.now()); return myObject; }
This works well, but I would like to set up one thing: if the returned Java object contains a property of the new Java 8 LocalDateTime type, it appears as a JSON object:
{"myDateTimeProperty":{"hour":14,"minute":32,"second":39,"year":2014,"month":"NOVEMBER","dayOfMonth":6,"dayOfWeek":"THURSDAY","dayOfYear":310,"monthValue":11,"nano":0,"chronology":{"calendarType":"iso8601","id":"ISO"}},...}
How can I tell JAX-RS to return a JavaScript string Date.toJSON (), for example
{"myDateTimeProperty":"2014-11-07T15:06:36.545Z",...}
instead
source share