public class JsonParser extends JsonParserBase
This JSON parser also works in lazy(boolean)
mode. This
mode is for top performance usage: parsing is done very, very lazy.
While you can use all the mappings and other tools, for best performance
the lazy mode should be used only with maps and lists (no special mappings).
Also, the performance has it's price: more memory consumption, because the
original input is hold until the result is in use.
See: http://www.ietf.org/rfc/rfc4627.txt
Modifier and Type | Class and Description |
---|---|
static class |
JsonParser.Defaults |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
classMetadataName |
protected java.util.Map<Path,ValueConverter> |
convs |
protected char[] |
input |
static java.lang.String |
KEYS
Map keys.
|
protected boolean |
lazy |
protected boolean |
looseMode |
protected java.util.Map<Path,java.lang.Class> |
mappings |
protected MapToBean |
mapToBean |
protected int |
ndx |
protected Path |
path |
protected java.lang.Class |
rootType |
protected char[] |
text |
protected int |
textLen |
protected int |
total |
protected boolean |
useAltPaths |
static java.lang.String |
VALUES
Array or map values.
|
ARRAYLIST_SUPPLIER, classnameWhitelist, HASHMAP_SUPPLIER, LAZYLIST_SUPPLIER, LAZYMAP_SUPPLIER, listSupplier, mapSupplier, strictTypes
Constructor and Description |
---|
JsonParser() |
Modifier and Type | Method and Description |
---|---|
JsonParser |
allowAllClasses()
Removes the whitelist of allowed classes.
|
JsonParser |
allowClass(java.lang.String classPattern)
Adds a
wildcard pattern for white-listing classes. |
protected void |
consume(char c)
Consumes char at current position.
|
protected char |
consumeOneOf(char c1,
char c2)
Consumes one of the allowed char at current position.
|
static JsonParser |
create()
Static ctor.
|
static JsonParser |
createLazyOne()
Creates a lazy implementation of the JSON parser.
|
protected void |
growAndCopy()
Grows text array when
text.length == textLen . |
protected void |
growEmpty()
Grows empty text array.
|
protected boolean |
isEOF()
Returns
true if scanning is at the end. |
JsonParser |
lazy(boolean lazy)
Defines how JSON parser works.
|
protected ValueConverter |
lookupValueConverter()
Lookups for value converter for current path.
|
JsonParser |
looseMode(boolean looseMode)
Enables 'loose' mode for parsing.
|
JsonParser |
map(java.lang.Class target)
Maps a class to JSONs root.
|
JsonParser |
map(java.lang.String path,
java.lang.Class target)
Maps a class to given path.
|
protected boolean |
match(char[] target)
Matches char buffer with content on given location.
|
<T> T |
parse(char[] input)
Parses input JSON char array.
|
<T> T |
parse(char[] input,
java.lang.Class<T> targetType)
Parses input JSON as given type.
|
<T> T |
parse(java.lang.String input)
Parses input JSON string.
|
<T> T |
parse(java.lang.String input,
java.lang.Class<T> targetType)
Parses input JSON as given type.
|
protected java.lang.Object |
parseArrayContent(java.lang.Class targetType,
java.lang.Class componentType)
Parses arrays, once when open bracket has been consumed.
|
JsonArray |
parseAsJsonArray(java.lang.String input)
Parses input JSON to
JsonArray , special case of parsing. |
JsonObject |
parseAsJsonObject(java.lang.String input)
Parses input JSON to
JsonObject , special case of parse(String, Class) . |
<T> java.util.List<T> |
parseAsList(java.lang.String string,
java.lang.Class<T> componentType)
Parses input JSON to a list with specified component type.
|
<K,V> java.util.Map<K,V> |
parseAsMap(java.lang.String string,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType)
Parses input JSON to a list with specified key and value types.
|
protected java.lang.Number |
parseNumber()
Parses JSON numbers.
|
protected java.lang.Object |
parseObjectContent(java.lang.Class targetType,
java.lang.Class valueKeyType,
java.lang.Class valueType)
Parses object, once when open bracket has been consumed.
|
protected java.lang.String |
parseString()
Parses a string.
|
protected java.lang.String |
parseStringContent(char quote)
Parses string content, once when starting quote has been consumed.
|
protected char |
parseUnicode()
Parses 4 characters and returns unicode character.
|
protected java.lang.String |
parseUnquotedStringContent()
Parses un-quoted string content.
|
protected java.lang.Object |
parseValue(java.lang.Class targetType,
java.lang.Class keyType,
java.lang.Class componentType)
Parses a JSON value.
|
protected java.lang.Class |
replaceWithMappedTypeForPath(java.lang.Class target)
Replaces type with mapped type for current path.
|
protected void |
reset()
Resets JSON parser, so it can be reused.
|
JsonParser |
setClassMetadataName(java.lang.String name)
Sets local class meta-data name.
|
protected void |
skipWhiteSpaces()
Skips whitespaces.
|
JsonParser |
strictTypes(boolean strictTypes)
Defines if type conversion is strict.
|
protected void |
syntaxError(java.lang.String message)
Throws
JsonException indicating a syntax error. |
JsonParser |
useAltPaths()
Enables usage of additional paths.
|
JsonParser |
withClassMetadata(boolean useMetadata)
Sets usage of default class meta-data name.
|
JsonParser |
withValueConverter(java.lang.String path,
ValueConverter valueConverter)
Defines
ValueConverter to use on given path. |
convertType, createMapToBean, injectValueIntoObject, newArrayInstance, newObjectInstance
public static final java.lang.String KEYS
public static final java.lang.String VALUES
protected int ndx
protected char[] input
protected int total
protected Path path
protected boolean useAltPaths
protected boolean lazy
protected boolean looseMode
protected java.lang.Class rootType
protected MapToBean mapToBean
protected java.util.Map<Path,java.lang.Class> mappings
protected java.util.Map<Path,ValueConverter> convs
protected java.lang.String classMetadataName
protected char[] text
protected int textLen
public static JsonParser create()
public static JsonParser createLazyOne()
protected void reset()
public JsonParser useAltPaths()
public JsonParser looseMode(boolean looseMode)
public JsonParser strictTypes(boolean strictTypes)
null
.public JsonParser lazy(boolean lazy)
public JsonParser map(java.lang.Class target)
public JsonParser map(java.lang.String path, java.lang.Class target)
values
to the path to specify component type (if not specified by
generics).protected java.lang.Class replaceWithMappedTypeForPath(java.lang.Class target)
public JsonParser withValueConverter(java.lang.String path, ValueConverter valueConverter)
ValueConverter
to use on given path.protected ValueConverter lookupValueConverter()
public JsonParser setClassMetadataName(java.lang.String name)
Note that by using the class meta-data name you may expose a security hole in case untrusted source manages to specify a class that is accessible through class loader and exposes set of methods and/or fields, access of which opens an actual security hole. Such classes are known as “deserialization gadget”s. Because of this, use of "default typing" is not encouraged in general, and in particular is recommended against if the source of content is not trusted. Conversely, default typing may be used for processing content in cases where both ends (sender and receiver) are controlled by same entity.
public JsonParser withClassMetadata(boolean useMetadata)
setClassMetadataName(String)
for more details.setClassMetadataName(String)
public JsonParser allowClass(java.lang.String classPattern)
wildcard
pattern for white-listing classes.setClassMetadataName(String)
public JsonParser allowAllClasses()
setClassMetadataName(String)
public <T> T parse(java.lang.String input, java.lang.Class<T> targetType)
public JsonObject parseAsJsonObject(java.lang.String input)
JsonObject
, special case of parse(String, Class)
.public JsonArray parseAsJsonArray(java.lang.String input)
JsonArray
, special case of parsing.public <T> java.util.List<T> parseAsList(java.lang.String string, java.lang.Class<T> componentType)
public <K,V> java.util.Map<K,V> parseAsMap(java.lang.String string, java.lang.Class<K> keyType, java.lang.Class<V> valueType)
public <T> T parse(java.lang.String input)
public <T> T parse(char[] input, java.lang.Class<T> targetType)
public <T> T parse(char[] input)
protected java.lang.Object parseValue(java.lang.Class targetType, java.lang.Class keyType, java.lang.Class componentType)
targetType
- target type to convert, may be null
componentType
- component type for maps and arrays, may be null
protected java.lang.String parseString()
protected java.lang.String parseStringContent(char quote)
protected void growEmpty()
protected void growAndCopy()
text.length == textLen
.protected char parseUnicode()
protected java.lang.String parseUnquotedStringContent()
protected java.lang.Number parseNumber()
protected java.lang.Object parseArrayContent(java.lang.Class targetType, java.lang.Class componentType)
protected java.lang.Object parseObjectContent(java.lang.Class targetType, java.lang.Class valueKeyType, java.lang.Class valueType)
protected void consume(char c)
protected char consumeOneOf(char c1, char c2)
0
.
If matched, returns matched char.protected boolean isEOF()
true
if scanning is at the end.protected final void skipWhiteSpaces()
protected final boolean match(char[] target)
protected void syntaxError(java.lang.String message)
JsonException
indicating a syntax error.Copyright © 2003-present Jodd Team