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

io.circe.generic.extras.encoding.UnwrappedEncoder.scala Maven / Gradle / Ivy

There is a newer version: 0.12.0-M3
Show newest version
package io.circe.generic.extras.encoding

import io.circe.{Encoder, Json}
import shapeless.{::, Generic, HNil, Lazy}

abstract class UnwrappedEncoder[A] extends Encoder[A]

final object UnwrappedEncoder {
  implicit def encodeUnwrapped[A <: AnyVal, R](
    implicit
    gen:    Lazy[Generic.Aux[A, R :: HNil]],
    encode: Encoder[R]
  ): UnwrappedEncoder[A] = new UnwrappedEncoder[A] {
    override def apply(a: A): Json =
      encode(gen.value.to(a).head)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy