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

yamusca.circe.package.scala Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
package yamusca

import io.circe._
import yamusca.converter.instances.seqValueConverter
import yamusca.imports._

package object circe {

  implicit def circeJsonNumberValueConverter(implicit
      vl: ValueConverter[Long],
      vd: ValueConverter[Double]
  ): ValueConverter[JsonNumber] =
    ValueConverter.of(n => n.toLong.map(vl).getOrElse(vd(n.toDouble)))

  implicit def circeJsonObjectValueConverter(implicit
      v: ValueConverter[Json]
  ): ValueConverter[JsonObject] =
    ValueConverter.of(obj =>
      Value.fromContext(Context.from(name => obj(name).map(v)), obj.isEmpty)
    )

  implicit def circeJsonValueConverter(implicit
      vb: ValueConverter[Boolean],
      vnum: ValueConverter[JsonNumber],
      vs: ValueConverter[String]
  ): ValueConverter[Json] =
    ValueConverter.of(
      _.fold(
        Value.of(None),
        b => vb(b),
        n => vnum(n),
        s => vs(s),
        vseq => seqValueConverter(circeJsonValueConverter)(vseq),
        obj => circeJsonObjectValueConverter(circeJsonValueConverter)(obj)
      )
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy