JsonParser
. When no target type is provided, the parser will convert JSON string to Java Map
and List
. Like this:Map
that contains 2 keys. One of the keys (one
) holds another Map
instance. As you can see from the example, simple JSON data types are converted into their counter-part Java types. Boolean value is converted to Boolean
, number is converted to a Number
or BigInteger
etc. JsonParser
finds the best possible type; for example, if number can be stored into an int
then Integer
is returned, but if it is a decimal value then Double
is returned and so on.name
is a simple property. But bars
is a Map
of Bars
:JsonParser
. It will parse inner JSON maps to Bar
types, since the generic type of the property specifies the map's content type. In the same way JsonParser
can handle the inters
map.JsonParser
now converts JSON directly to a target type. Let's remember:JsonParser
lookups for type information from the target's property: the property type and generics information.JsonParser
can parse complex JSON strings into Java object graph, as long it can resolve the type information.Inter
is an interface:JsonParser
that can't figure out by looking at the inters
property types and its generic information. We need to explicitly specify the target type for maps values. As you could guess, we can use a path to specify the mapping. But in this case, the path needs to address the values of the map! No problem - by using a special path name value
we can address all the values of a map:value
, we could specify the key's type, using the path reference keys
. Look at the following example:map()
method to map the target type in the result object graph, specified by its path.Pair
of two different types.values
or keys
to reference ALL values of a map or ALL keys of a map (or of an array). But you can not change the type of particular map value, since these special paths address ALL items..useAltPaths()
we are telling JsonParser
to match paths to current map values! By default, this option is disabled, for performance reasons (there is some penalty because more paths are matched).class
or __class
. If you have such JSON or if you have used this option with JsonSerializer
, you can enable this feature with JsonParser
as well:class
that holds the full class name of the target. But be careful:JsonParser
has some performance penalty and may introduce a potential security risk. Map
so we can fetch the class name and then converted to a target class. Because of this double conversion expect performance penalties if using class metadata name.allowClass()
. If the class name does not match one of set wildcard patterns, JsonParser
will throw an exception. To reset the whitelist, use allowAllClasses()
.JoddParser
uses powerful TypeConverter
to convert between strings to real types.Date
may be specified as a string in yyyy/MM/dd
format and not as a number of milliseconds. So we need to explicitly convert the string into Date
. For that, we can use ValueConverter
:JsonParser
may run in so-called loose mode, when it can process more:JsonParser
in loose mode may parse the following input:Map
or the List
i.e. in the lazy mode, there is no sense to parse to concrete types. The returned object is lazy since the parsing happens only on key retrieval.