trait JsonCodec[A] extends JsonDecoder[A] with JsonEncoder[A]

A JsonCodec[A] instance has the ability to encode values of type A into JSON, together with the ability to decode such JSON into values of type A.

The trait is the intersection composition of JsonDecoder[A] and JsonEncoder[A], and instances should satisfy round-tripping laws: that is, for every value, instances must be able to successfully encode the value into JSON, and then successfully decode the same value from such JSON.

For more information, see JsonDecoder and JsonEncoder.

{{ val intCodec: JsonCodec[Int] = JsonCodec[Int]

intCodec.encodeJson(intCodec.encodeJson(42)) == Right(42) }}

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JsonCodec
  2. JsonEncoder
  3. JsonEncoderPlatformSpecific
  4. JsonDecoder
  5. JsonDecoderPlatformSpecific
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def decoder: JsonDecoder[A]
  2. abstract def encoder: JsonEncoder[A]
  3. abstract def unsafeDecode(trace: List[JsonError], in: RetractReader): A

    Low-level, unsafe method to decode a value or throw an exception.

    Low-level, unsafe method to decode a value or throw an exception. This method should not be called in application code, although it can be implemented for user-defined data structures.

    Definition Classes
    JsonDecoder
  4. abstract def unsafeEncode(a: A, indent: Option[Int], out: Write): Unit
    Definition Classes
    JsonEncoder

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def *>[B](that: => JsonDecoder[B]): JsonDecoder[B]

    An alias for JsonDecoder#zipRight.

    An alias for JsonDecoder#zipRight.

    Definition Classes
    JsonDecoder
  4. final def <*[B](that: => JsonDecoder[B]): JsonDecoder[A]

    An alias for JsonDecoder#zipLeft.

    An alias for JsonDecoder#zipLeft.

    Definition Classes
    JsonDecoder
  5. final def <*>[B](that: => JsonDecoder[B]): JsonDecoder[(A, B)]

    An alias for JsonDecoder#zip.

    An alias for JsonDecoder#zip.

    Definition Classes
    JsonDecoder
  6. final def <+>[B](that: => JsonDecoder[B]): JsonDecoder[Either[A, B]]

    An alias for JsonDecoder#orElseEither.

    Definition Classes
    JsonDecoder
  7. final def <>[A1 >: A](that: => JsonDecoder[A1]): JsonDecoder[A1]

    An alias for JsonDecoder#orElse.

    An alias for JsonDecoder#orElse.

    Definition Classes
    JsonDecoder
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. final def both[B](that: => JsonEncoder[B]): JsonEncoder[(A, B)]

    Returns a new encoder that is capable of encoding a tuple containing the values of this encoder and the specified encoder.

    Returns a new encoder that is capable of encoding a tuple containing the values of this encoder and the specified encoder.

    Definition Classes
    JsonEncoder
  11. final def bothWith[B, C](that: => JsonEncoder[B])(f: (C) => (A, B)): JsonEncoder[C]

    Returns a new encoder that is capable of encoding a user-defined value, which is create from a tuple of the values of this encoder and the specified encoder, from the specified user- defined function.

    Returns a new encoder that is capable of encoding a user-defined value, which is create from a tuple of the values of this encoder and the specified encoder, from the specified user- defined function.

    Definition Classes
    JsonEncoder
  12. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  13. final def contramap[B](f: (B) => A): JsonEncoder[B]

    Returns a new encoder, with a new input type, which can be transformed to the old input type by the specified user-defined function.

    Returns a new encoder, with a new input type, which can be transformed to the old input type by the specified user-defined function.

    Definition Classes
    JsonEncoder
  14. final def decodeJson(str: CharSequence): Either[String, A]

    Attempts to decode a value of type A from the specified CharSequence, but may fail with a human-readable error message if the provided text does not encode a value of this type.

    Attempts to decode a value of type A from the specified CharSequence, but may fail with a human-readable error message if the provided text does not encode a value of this type.

    Note: This method may not entirely consume the specified character sequence.

    Definition Classes
    JsonDecoder
  15. final def either[B](that: => JsonEncoder[B]): JsonEncoder[Either[A, B]]

    Returns a new encoder that can accepts an Either[A, B] to either, and uses either this encoder or the specified encoder to encode the two different types of values.

    Returns a new encoder that can accepts an Either[A, B] to either, and uses either this encoder or the specified encoder to encode the two different types of values.

    Definition Classes
    JsonEncoder
  16. final def eitherWith[B, C](that: => JsonEncoder[B])(f: (C) => Either[A, B]): JsonEncoder[C]

    Returns a new encoder with a new input type, which can be transformed to either the input type of this encoder, or the input type of the specified encoder, using the user-defined transformation function.

    Returns a new encoder with a new input type, which can be transformed to either the input type of this encoder, or the input type of the specified encoder, using the user-defined transformation function.

    Definition Classes
    JsonEncoder
  17. final def encodeJson(a: A, indent: Option[Int]): CharSequence

    Encodes the specified value into a JSON string, with the specified indentation level.

    Encodes the specified value into a JSON string, with the specified indentation level.

    Definition Classes
    JsonEncoder
  18. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  20. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  21. def fromJsonAST(json: Json): Either[String, A]

    Decode a value from an already parsed Json AST.

    Decode a value from an already parsed Json AST.

    The default implementation encodes the Json to a byte stream and uses decode to parse that. Override to provide a more performant implementation.

    Definition Classes
    JsonDecoder
  22. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  24. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  25. def isNothing(a: A): Boolean

    This default may be overriden when this value may be missing within a JSON object and still be encoded.

    This default may be overriden when this value may be missing within a JSON object and still be encoded.

    Definition Classes
    JsonEncoder
    Annotations
    @nowarn()
  26. def map[B](f: (A) => B): JsonDecoder[B]

    Returns a new codec whose decoded values will be mapped by the specified function.

    Returns a new codec whose decoded values will be mapped by the specified function.

    Definition Classes
    JsonDecoder
  27. final def mapOrFail[B](f: (A) => Either[String, B]): JsonDecoder[B]

    Returns a new codec whose decoded values will be mapped by the specified function, which may itself decide to fail with some type of error.

    Returns a new codec whose decoded values will be mapped by the specified function, which may itself decide to fail with some type of error.

    Definition Classes
    JsonDecoder
  28. final def narrow[B <: A]: JsonEncoder[B]

    Returns this encoder but narrowed to the its given sub-type

    Returns this encoder but narrowed to the its given sub-type

    Definition Classes
    JsonEncoder
  29. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  30. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  31. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  32. final def orElse[A1 >: A](that: => JsonDecoder[A1]): JsonDecoder[A1]

    Returns a new codec that combines this codec and the specified codec using fallback semantics: such that if this codec fails, the specified codec will be tried instead.

    Returns a new codec that combines this codec and the specified codec using fallback semantics: such that if this codec fails, the specified codec will be tried instead. This method may be unsafe from a security perspective: it can use more memory than hand coded alternative and so lead to DOS.

    For example, in the case of an alternative between Int and Boolean, a hand coded alternative would look like:

    val decoder: JsonDecoder[AnyVal] = JsonDecoder.peekChar[AnyVal] { case 't' | 'f' => JsonDecoder[Boolean].widen case c => JsonDecoder[Int].widen }

    Definition Classes
    JsonDecoder
  33. final def orElseEither[B](that: => JsonDecoder[B]): JsonDecoder[Either[A, B]]

    Returns a new codec that combines this codec and the specified codec using fallback semantics: such that if this codec fails, the specified codec will be tried instead.

    Returns a new codec that combines this codec and the specified codec using fallback semantics: such that if this codec fails, the specified codec will be tried instead.

    Definition Classes
    JsonDecoder
  34. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  35. def toJsonAST(a: A): Either[String, Json]

    Converts a value to a Json AST

    Converts a value to a Json AST

    The default implementation encodes the value to a Json byte stream and uses decode to parse that back to an AST. Override to provide a more performant implementation.

    Definition Classes
    JsonEncoder
  36. def toString(): String
    Definition Classes
    AnyRef → Any
  37. def unsafeDecodeMissing(trace: List[JsonError]): A
    Definition Classes
    JsonDecoder
  38. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  39. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  40. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  41. final def widen[B >: A]: JsonDecoder[B]

    Returns this decoder but widened to the its given super-type

    Returns this decoder but widened to the its given super-type

    Definition Classes
    JsonDecoder
  42. def xmap[B](f: (A) => B, g: (B) => A): JsonCodec[B]
    Definition Classes
    JsonCodecJsonEncoderJsonDecoder
  43. final def zip[B](that: => JsonDecoder[B]): JsonDecoder[(A, B)]

    Returns a new codec that combines this codec and the specified codec into a single codec that decodes a tuple of the values decoded by the respective codecs.

    Returns a new codec that combines this codec and the specified codec into a single codec that decodes a tuple of the values decoded by the respective codecs.

    Definition Classes
    JsonDecoder
  44. final def zipLeft[B](that: => JsonDecoder[B]): JsonDecoder[A]

    Zips two codecs, but discards the output on the right hand side.

    Zips two codecs, but discards the output on the right hand side.

    Definition Classes
    JsonDecoder
  45. final def zipRight[B](that: => JsonDecoder[B]): JsonDecoder[B]

    Zips two codecs, but discards the output on the left hand side.

    Zips two codecs, but discards the output on the left hand side.

    Definition Classes
    JsonDecoder
  46. final def zipWith[B, C](that: => JsonDecoder[B])(f: (A, B) => C): JsonDecoder[C]

    Zips two codecs into one, transforming the outputs of both codecs by the specified function.

    Zips two codecs into one, transforming the outputs of both codecs by the specified function.

    Definition Classes
    JsonDecoder

Inherited from JsonEncoder[A]

Inherited from JsonEncoderPlatformSpecific[A]

Inherited from JsonDecoder[A]

Inherited from JsonDecoderPlatformSpecific[A]

Inherited from AnyRef

Inherited from Any

Ungrouped