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

io.circe.generic.extras.decoding.UnwrappedDecoder.scala Maven / Gradle / Ivy

There is a newer version: 0.11.2
Show newest version
package io.circe.generic.extras.decoding

import io.circe.{ Decoder, HCursor }
import shapeless.{ ::, Generic, HNil, Lazy }

abstract class UnwrappedDecoder[A] extends Decoder[A]

final object UnwrappedDecoder {
  implicit def decodeUnwrapped[A, R](
    implicit
    gen: Lazy[Generic.Aux[A, R :: HNil]],
    decode: Decoder[R]
  ): UnwrappedDecoder[A] = new UnwrappedDecoder[A] {
    override def apply(c: HCursor): Decoder.Result[A] =
      decode(c) match {
        case Right(unwrapped) => Right(gen.value.from(unwrapped :: HNil))
        case l @ Left(_)      => l.asInstanceOf[Decoder.Result[A]]
      }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy