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

ujson.Transformable.scala Maven / Gradle / Ivy

There is a newer version: 0.6.3
Show newest version
package ujson

import java.nio.ByteBuffer
import java.nio.channels.ReadableByteChannel

abstract class Transformable {
  def transform[T](f: ujson.Visitor[_, T]): T
}

object Transformable {
  case class fromTransformer[T](t: T, w: Transformer[T]) extends Transformable{
    def transform[T](f: ujson.Visitor[_, T]): T = {
      w.transform(t, f)
    }
  }
  implicit def fromString(s: String) = new fromTransformer(s, StringParser)
  implicit def fromCharSequence(s: CharSequence) = new fromTransformer(s, CharSequenceParser)
  implicit def fromChannel(s: ReadableByteChannel) = new fromTransformer(s, ChannelParser)
  implicit def fromPath(s: java.nio.file.Path) = new fromTransformer(s, PathParser)
  implicit def fromFile(s: java.io.File) = new fromTransformer(s, FileParser)
  implicit def fromByteBuffer(s: ByteBuffer) = new fromTransformer(s, ByteBufferParser)
  implicit def fromByteArray(s: Array[Byte]) = new fromTransformer(s, ByteArrayParser)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy