Open DavidPerezIngeniero opened 1 month ago
@DavidPerezIngeniero Yes, 'scala.concurrent.duration.Duration
is not supported yet for automatic derivation of codecs.
So, if using of java.time.Duration
is not an option, then need to write a custom codec.
Thanks!
Possible implementation:
given JsonValueCodec[Duration] with
override def decodeValue(in: JsonReader, default: Duration): Duration =
val l = in.readLong()
if (l == -1) Duration.Inf else Duration.fromNanos(l)
override def encodeValue(x: Duration, out: JsonWriter): Unit =
out.writeVal(if (x == Duration.Inf) -1 else x.toNanos)
override def nullValue: Duration = Duration.Inf
When trying:
I receive this strange error message:
For me, the error message is not explanatory enough. Should I write a custom serializer for Durations?