public class JsonParser
extends java.lang.Object
See: http://www.ietf.org/rfc/rfc4627.txt
todo: add factory for Maps and Lists
| Modifier and Type | Field and Description |
|---|---|
protected char[] |
input |
protected java.util.Map<Path,java.lang.Class> |
mappings |
protected int |
ndx |
protected Path |
path |
protected char[] |
text |
protected int |
textLen |
protected int |
total |
| Constructor and Description |
|---|
JsonParser() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
consume(char c)
Consumes char at current position.
|
protected java.lang.Object |
convertType(java.lang.Object value,
java.lang.Class targetType)
Converts type of the given value.
|
protected void |
grow()
Grows text array.
|
protected void |
injectValueIntoObject(java.lang.Object target,
jodd.introspector.PropertyDescriptor pd,
java.lang.Object value)
Injects value into the targets property.
|
protected boolean |
isEOF()
Returns
true if scanning is at the end. |
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.
|
protected java.lang.Object |
newArrayInstance(java.lang.Class targetType)
Creates new type for JSON array objects.
|
protected java.lang.Object |
newObjectInstance(java.lang.Class targetType)
Creates new object or a
HashMap if type is not specified. |
java.lang.Object |
parse(char[] input)
Parses input JSON char array.
|
<T> T |
parse(char[] input,
java.lang.Class<T> targetType)
Parses input JSON as given type.
|
java.lang.Object |
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.
|
protected java.lang.Number |
parseNumber()
Parses JSON numbers.
|
protected java.lang.Object |
parseObjectContent(java.lang.Class targetType,
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()
Parses string content, once when starting quote has been consumer.
|
protected char |
parseUnicode()
Parses 4 characters and returns unicode character.
|
protected java.lang.Object |
parseValue(java.lang.Class targetType,
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.
|
protected java.lang.Class |
resolveComponentType(jodd.introspector.PropertyDescriptor pd)
Resolves component type for given property descriptor.
|
protected jodd.introspector.PropertyDescriptor |
resolveSimpleProperty(java.lang.Class type,
java.lang.String key)
Resolves property type for given object.
|
protected void |
skipWhiteSpaces()
Skips whitespaces.
|
protected void |
syntaxError(java.lang.String message)
Throws
JsonException indicating a syntax error. |
protected int ndx
protected char[] input
protected int total
protected Path path
protected java.util.Map<Path,java.lang.Class> mappings
protected char[] text
protected int textLen
protected void reset()
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 <T> T parse(java.lang.String input,
java.lang.Class<T> targetType)
public java.lang.Object parse(java.lang.String input)
public <T> T parse(char[] input,
java.lang.Class<T> targetType)
public java.lang.Object parse(char[] input)
protected java.lang.Object parseValue(java.lang.Class targetType,
java.lang.Class componentType)
targetType - target type to convert, may be nullcomponentType - component type for maps and arrays, may be nullprotected java.lang.String parseString()
protected java.lang.String parseStringContent()
protected void grow()
protected char parseUnicode()
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 valueType)
protected void consume(char c)
protected boolean isEOF()
true if scanning is at the end.protected final void skipWhiteSpaces()
protected final boolean match(char[] target)
protected java.lang.Object newObjectInstance(java.lang.Class targetType)
HashMap if type is not specified.protected java.lang.Object newArrayInstance(java.lang.Class targetType)
protected jodd.introspector.PropertyDescriptor resolveSimpleProperty(java.lang.Class type,
java.lang.String key)
null when property type is unknown (either property is missing
or targets type is a map).protected java.lang.Class resolveComponentType(jodd.introspector.PropertyDescriptor pd)
protected void injectValueIntoObject(java.lang.Object target,
jodd.introspector.PropertyDescriptor pd,
java.lang.Object value)
protected java.lang.Object convertType(java.lang.Object value,
java.lang.Class targetType)
protected void syntaxError(java.lang.String message)
JsonException indicating a syntax error.Copyright © 2003-2013 Jodd Team