Marcus Ilgner
07/25/2023, 1:32 PMdata class DataPoint {
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "UTC")
val time: Instant,
}
val mapper = jacksonObjectMapper()
mapper.registerModule(JavaTimeModule())
val dataPoint = DataPoint(time = Instant.parse("2001-09-09T01:46:40Z"))
val encoded = mapper.writeValueAsString(dataPoint)
assertEquals(
"{\"time\":\"2001-09-09T01:46:40Z\"}",
encoded,
)
Unfortunately the encoded value for time
looks like this an object, even though the shape was set to `STRING`:
{
"time": {
"epochSeconds": 1000000000,
"value$kotlinx_datetime": "2001-09-09T01:46:40Z",
"nanosecondsOfSecond": 0
}
}
any ideas?dinomite
07/26/2023, 3:03 PM@field:JsonFormat
might do what you want https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets