com.paypal.cascade.json

JsonUtil

object JsonUtil

Patterns adapted from https://coderwall.com/p/o--apg

Known caveats:

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. JsonUtil
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def convertValue[T](obj: Any)(implicit arg0: Manifest[T]): Try[T]

    Convert an arbitrary JSON object to a T, where T is some context bound type.

    Convert an arbitrary JSON object to a T, where T is some context bound type. Useful for secondary JSON conversion, e.g. for polymorphic data members. A direct use-case is in JSON-Patch, where the expected value may be any of a raw value (String, Int, etc.), a full JSON object, or nothing.

    import com.paypal.cascade.json._
    case class JsonPatch(op: String, path: String, value: Option[Any])
    case class AnObject(...)
    val jsonStr = JsonUtil.toJson(JsonPatch("add", "/-", Some(AnObject(...)))).get
    val a = JsonUtil.fromJson[JsonPatch](jsonStr).get
    val inner = JsonUtil.convertValue[Option[AnObject]](a.value).get
    T

    a context bound type

    obj

    the object to convert

    returns

    a scala.util.Try that is either the object of type T, or a java.lang.IllegalArgumentException in the case of a cast to an incompatible type.

    Note

    Discovered via testing, this method does not play well with Optional data stored in Any fields. If you know that you need to serialize Optional values, please state them as Optional in their type declaration, e.g. in the example here with Foo and Bar. If a None is serialized in an object with an Any field, and you try to convert this as an Option, it will instead come out as a null value and you will have to post-process it as such. Instead, if the field is declared as a Option[Any] and a None is serialized, it will correctly be converted here as a None.

    ,

    This proxy method exists as an alternative to exposing the entire private mapper through a getInstance or copy method, so that the mapper remains a strict singleton and its configuration remains obscured. Otherwise, this is a direct proxy of the mapper.convertValue method from ScalaObjectMapper in Jackson, with added exception catching.

    ,

    In general, fromJson should be preferred for String-to-Object conversion. This method is intended for secondary conversion after fromJson has been applied.

  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def fromJson[T](json: String)(implicit arg0: Manifest[T]): Try[T]

    Convert a JSON string to a T, where T is some context bound type.

    Convert a JSON string to a T, where T is some context bound type.

    T

    a context bound type

    json

    the JSON string

    returns

    a scala.util.Try that is either the object of type T, or one of java.io.IOException, com.fasterxml.jackson.core.JsonParseException, or com.fasterxml.jackson.databind.JsonMappingException

  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  20. def toJson(value: Any): Try[String]

    Convert an object to a JSON string representation.

    Convert an object to a JSON string representation.

    value

    the object to convert

    returns

    a scala.util.Try that is either the JSON string representation, or a com.fasterxml.jackson.core.JsonProcessingException

  21. def toString(): String

    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped