yamusca.circe.package.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yamusca-circe_sjs1_3 Show documentation
Show all versions of yamusca-circe_sjs1_3 Show documentation
Provide value converter for circes json values
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