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

sangria.marshalling.SymmetricMarshaller.scala Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package sangria.marshalling

trait SymmetricMarshaller[T] {
  def marshaller: ResultMarshaller
  def inputUnmarshaller: InputUnmarshaller[T]
}

object SymmetricMarshaller extends SymmetricMarshallerLowProImplicits {
  case class DefaultSymmetricMarshaller[T](marshaller: ResultMarshaller, inputUnmarshaller: InputUnmarshaller[T]) extends SymmetricMarshaller[T]

  implicit def symmetric[T : ResultMarshallerForType : InputUnmarshaller]: SymmetricMarshaller[T] =
    DefaultSymmetricMarshaller(implicitly[ResultMarshallerForType[T]].marshaller, implicitly[InputUnmarshaller[T]])
}

abstract class SymmetricMarshallerLowProImplicits {
  val defaultInput =
    SymmetricMarshaller.DefaultSymmetricMarshaller[Any](
      scalaMarshalling.scalaResultMarshaller,
      scalaMarshalling.scalaInputUnmarshaller[Any].asInstanceOf[InputUnmarshaller[Any]])

  // `T =:= Any` is the only constraint that makes type inference work
  implicit def default[T](implicit ev: T =:= Any): SymmetricMarshaller[T] = defaultInput.asInstanceOf[SymmetricMarshaller[T]]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy