com.ancientlightstudios.quarkus.kotlin.openapi.extension.InstantSupport.kt Maven / Gradle / Ivy
package com.ancientlightstudios.quarkus.kotlin.openapi.extension
import com.ancientlightstudios.quarkus.kotlin.openapi.*
import com.fasterxml.jackson.databind.JsonNode
import java.time.Instant
fun Maybe.asInstant(): Maybe = onNotNull {
try {
success(Instant.parse(value))
} catch (e: Exception) {
failure(ValidationError("Invalid instant.", context))
}
}
@JvmName("asInstantFromJson")
fun Maybe.asInstant(): Maybe = asString().asInstant()
@JvmName("asStringFromInstant")
fun Instant.asString(): String = toString()
fun Instant.asJson(): JsonNode = asString().asJson()