0

We are using CXF in combination with Jackson (JacksonJaxbJsonProvider) to marshall domain objects into JSON. Everything is working good, with the exception that I cannot get dates to format the way I want them to. In short, what I want, is to output dates as seconds since epoch (also called unix time). This is partly doable with SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, but this gives me milliseconds, not seconds. As my dates don't have such high precision (and never will), I am wasting 4 bytes for every timestamp.

To my knowledge, the only way I can control the date format is by using setDateFormat() on ObjectMapper. This function accepts a DateFormat. However, it does not seem like a DateFormat can output seconds since epoch, only milliseconds.

Are there any other ways of doing this?

Bendik
  • 928
  • 11
  • 23
  • You'd need to write a custom serializer/deserializer. But why is it so important? Just `/ 1000` in your code... – fge Feb 12 '14 at 09:11
  • It's important because I need to minimize the amount of data as much as possible. It also feels wrong to send unnecessary large amounts of data to the clients just because CXF/Jackson says so. If you feel a custom serializer/deserializer is the best bet, could you perhaps come up with an answer? That way I could mark it as correct :) – Bendik Feb 12 '14 at 11:26
  • An XmlAdapter is what you want. Check this out: http://stackoverflow.com/a/3181966. – Patrick Feb 12 '14 at 21:12

0 Answers0