Reputation: 1480
Based on what's described here, I should be serialising ZonedDateTime
object using the JSR-310 representation rather than the numeric one. However, I'm getting the numeric representation. What could be the problem?
This is how I configure the mapper I'm using:
object JsonFormatter {
private val mapper = new ObjectMapper() with ScalaObjectMapper
mapper
.registerModule(DefaultScalaModule)
.registerModule(new JavaTimeModule())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
def fromJson[T](json: String)(implicit m: Manifest[T]): T = mapper.readValue[T](json.getBytes)
def toJson(value: Any): String = mapper.writeValueAsString(value)
}
This is an example of deserialisation I get
{"from":"CityA","to":"CityB","departureAt":1554970560.000000000,"arriveAt":1554984660.000000000,"duration":{"length":65,"unit":"MINUTES","finite":true}}
for the following case class:
case class Stock(from: String,
to: String,
departureAt: ZonedDateTime,
arriveAt: ZonedDateTime,
duration: Duration)
Upvotes: 0
Views: 67
Reputation: 1480
Apparently WRITE_DATES_AS_TIMESTAMPS
feature is enabled by default so I had to disable it by adding:
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
Upvotes: 2