All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala-http4s.modelsPackage.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>licenseInfo}}
package {{packageName}}

import io.circe.{Decoder, Encoder, Json}
import java.time.{Instant, LocalDate, OffsetDateTime}
import java.util.UUID

package object models {

  given decodeUUID: Decoder[UUID] =
    Decoder.decodeString.map(str => UUID.fromString(str))

  given encodeUUID: Encoder[UUID] =
    Encoder.encodeString.contramap[UUID](uuid => uuid.toString)

  given decodeInstant: Decoder[Instant] =
    Decoder.decodeString.map(str => OffsetDateTime.parse(str).toInstant)

  given encodeInstant: Encoder[Instant] =
    Encoder.encodeString.contramap[Instant](_.toString)

  given decodeLocalDate: Decoder[LocalDate] =
    Decoder.decodeString.map(str => LocalDate.parse(str))

  given encodeLocalDate: Encoder[LocalDate] =
    Encoder.encodeString.contramap[LocalDate](_.toString)

  given decodeJson: Decoder[Json] =
    Decoder.decodeString.map(str => Json.fromString(str))

  given encodeJson: Encoder[Json] =
    Encoder.encodeString.contramap[Json](_.toString)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy