io.github.netvl.picopickle.TypesComponent
Creates a reader using the given partial function.
Creates a reader using the given partial function.
This is the main constructor for custom readers. The provided partial function is used to reconstruct a value from its backend representation. canRead method of the constructed reader delegates to isDefinedAt on the partial function.
An example:
case class A(x: Int, y: String) implicit val aReader: Reader[A] = Reader { case backend.Extract.Object(m) if m.contains("a") && m.contains("b") && backend.getNumber(m("a")).isDefined && backend.getString(m("b")).isDefined => A( backend.Extract.Number.unapply(m("a")).get, backend.Extract.String.unapply(m("b")).get ) }
As manual deconstruction of complex object may quickly turn very unwieldy, it is recommended to use converters instead.
target type
a partial function from backend representation to the target type
a reader delegating to the provided function.
Contains various constructors for custom Readers.