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.
a context bound type
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.
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, Unmarshallable.fromJson should be preferred for String-to-Object conversion. This method is intended for secondary conversion after Unmarshallable.fromJson has been applied.
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.
a context bound type
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
Convert an object to a JSON string representation.
Convert an object to a JSON string representation.
a scala.util.Try that is either the JSON string representation, or a com.fasterxml.jackson.core.JsonProcessingException
Implicit conversions from a JSON String to a variety of object types.