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

argonaut.JsonIdentity.scala Maven / Gradle / Ivy

There is a newer version: 6.3.10
Show newest version
package argonaut

class JsonIdentity[J](val j: J) extends AnyVal {

  /**
   * Encode to a JSON value using the given implicit encoder.
   */
  def jencode(implicit e: EncodeJson[J]): Json = e(j)

  /**
   * Encode to a JSON value using the given implicit encoder. Alias for `jencode`.
   */
  def asJson(implicit e: EncodeJson[J]): Json = jencode

  /**
    * Encode to a JSONNumber.
    */
  def asJsonNumber(implicit asn: EncodeJsonNumber[J]): JsonNumber = asn.encodeJsonNumber(j)

  /**
    * Encode to a JSONNumber, wrapped in a Some if it is valid, otherwise a None.
    */
  def asPossibleJsonNumber(implicit asn: EncodePossibleJsonNumber[J]): Option[JsonNumber] = asn.possiblyEncodeJsonNumber(j)
}

object JsonIdentity extends JsonIdentitys

trait JsonIdentitys {
  implicit def ToJsonIdentity[J](k: J): JsonIdentity[J] =
    new JsonIdentity[J](k)

  implicit def FromJsonIdentity[J](k: JsonIdentity[J]): J = k.j
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy