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

tethys.derivation.AutoDerivation.scala Maven / Gradle / Ivy

package tethys.derivation

import scala.quoted.*

import tethys.{JsonObjectWriter, JsonReader}
import tethys.commons.LowPriorityInstance
import tethys.derivation.impl.derivation.AutoDerivationMacro

trait AutoDerivation {
  implicit inline def jsonWriterMaterializer[T]: LowPriorityInstance[JsonObjectWriter[T]] =
    ${ AutoDerivation.jsonWriterMaterializer[T] }
    
  implicit inline def jsonReaderMaterializer[T]: LowPriorityInstance[JsonReader[T]] =
    ${ AutoDerivation.jsonReaderMaterializer[T] }
}

private[this] object AutoDerivation {
  def jsonWriterMaterializer[T: Type](using Quotes): Expr[LowPriorityInstance[JsonObjectWriter[T]]] =
    new AutoDerivationMacro(quotes).simpleJsonWriter[T]

  def jsonReaderMaterializer[T: Type](using Quotes): Expr[LowPriorityInstance[JsonReader[T]]] =
    new AutoDerivationMacro(quotes).simpleJsonReader[T]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy