JavaDurationSerializer

Serializer for java.time.Duration. All possible Hocon duration formats [https://github.com/lightbend/config/blob/main/HOCON.md#duration-format] are accepted for decoding. During encoding, the serializer emits values using time unit short names: d, h, m, s, ms, us, ns. The largest integer time unit is encoded. Example: 120.seconds -> 2 m; 121.seconds -> 121 s; 120.minutes -> 2 h; 122.minutes -> 122 m; 24.hours -> 1 d. When encoding, there is a conversion to kotlin.time.Duration. All restrictions on the maximum and minimum duration are specified in kotlin.time.Duration. Usage example:

@Serializable
data class ExampleDuration(
@Serializable(JDurationSerializer::class)
val duration: java.time.Duration
)
val config = ConfigFactory.parseString("duration = 1 day")
val exampleDuration = Hocon.decodeFromConfig(ExampleDuration.serializer(), config)
val newConfig = Hocon.encodeToConfig(ExampleDuration.serializer(), exampleDuration)

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): Duration
Link copied to clipboard
open override fun serialize(encoder: Encoder, value: Duration)