Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
uPickle Serializer
trait Api {
def read[T: Reader](s: Transformable): T = s.transform(reader[T])
def readJs[T: Reader](s: Js.Value): T = s.transform(reader[T])
def reader[T: Reader] = implicitly[Reader[T]]
def write[T: Writer](t: T, indent: Int = -1): String = {
def writeJs[T: Writer](t: T): Js.Value = transform(t).to[Js.Value]
def writeTo[T: Writer](t: T, out:, indent: Int = -1): Unit = {
transform(t).to(new Renderer(out, indent = indent))
def writer[T: Writer] = implicitly[Writer[T]]
def writable[T: Writer](t: T): Transformable = Transformable.fromTransformer(t, writer[T])
def readwriter[T: ReadWriter] = implicitly[ReadWriter[T]]
case class transform[T: Writer](t: T) extends Transformable{
def transform[V](f: ujson.Visitor[_, V]): V = writer[T].transform(t, f)
def to[V](f: ujson.Visitor[_, V]): V = transform(f)
def to[V](implicit f: Reader[V]): V = transform(f)
// End Api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment