0

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)

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.