2

Is there a way to define timestamp serialisation in restful webservices, so I can exclude time zone?

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Dto getById(@PathParam("id") Id id) { /**...**/ }

This produces json carrying timestamps formatted like this: 2014-12-14T16:29:52.416371+02:00

and I need only: 2014-12-14T16:29:52.416371

EDIT ISO 8601 format would do fine instead

2 Answers2

0

If you use Jackson for your JSON serializer there are several ways of doing custom serialization. You can read more here.

One of the ways of doing it is to use @JsonSerialize annotation with a class that extends JsonSerializer<T>

Simon
  • 6,293
  • 2
  • 28
  • 34
0

You can do this in a serializer and JAX-RS implementation independent way if you implement a custom entity provider / MessageBodyWriter. See: the JAX-RS user's guide section on this topic

NBW
  • 1,467
  • 2
  • 18
  • 27