public class Unmarshaller extends java.lang.Object implements UnmarshallerInterface
Unmarshaller is the main class for parsing json data, either a js object, an array or a simple primitive ((plain number, string, etc..). When parsing a js object, target is expected to be a java bean, therefore class MUST include setter and getter. parsing is done with reflection by looking for a method matching pramameters names. It can also work with generics.
See contructor and method for description see sample project for usage
JSONContext
Modifier and Type | Field and Description |
---|---|
protected JSONContext |
context |
Modifier | Constructor and Description |
---|---|
protected |
Unmarshaller(JSONContext context) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
parseArray(java.lang.Class obj,
java.lang.Class generic,
java.lang.String data)
sub parser for an array type ([] not Array() ).
|
protected java.lang.Object |
parseList(SerieConverterInterface parser,
java.lang.Class generic,
java.lang.String data)
sub parser for a list type.
|
java.lang.Object |
unmarshal(java.lang.Class object,
java.lang.Class generic,
java.lang.String data)
sub parser for a list type.
|
java.lang.Object |
unmarshal(java.lang.Class object,
java.lang.String data)
unmarshal a js string and return a java object.
|
protected final JSONContext context
protected Unmarshaller(JSONContext context)
public java.lang.Object unmarshal(java.lang.Class object, java.lang.String data) throws ParserException, java.lang.InstantiationException, java.lang.IllegalAccessException, SourceFormatException
the method decompose the source string into primitive, array, and js object. It will try to found a converter, if it fail, it will assume the target is a bean. note for bean class MUST include setter and getter. parsing is done with reflection by looking for a method matching pramameters names. It can also work with generics.
object
- expected object typedata
- json source dataParserException
- : error in parsing. can be unknow parserjava.lang.InstantiationException
java.lang.IllegalAccessException
- if tried to set non public param and nice is falseSourceFormatException
- if error detected in sourcepublic java.lang.Object unmarshal(java.lang.Class object, java.lang.Class generic, java.lang.String data) throws ParserException, java.lang.InstantiationException, java.lang.IllegalAccessException, SourceFormatException
UnmarshallerInterface
unmarshal
in interface UnmarshallerInterface
ParserException
SourceFormatException
java.lang.InstantiationException
java.lang.IllegalAccessException
protected java.lang.Object parseList(SerieConverterInterface parser, java.lang.Class generic, java.lang.String data) throws ParserException, SourceFormatException, java.lang.InstantiationException, java.lang.IllegalAccessException
parser
- generic
- data
- ParserException
SourceFormatException
java.lang.InstantiationException
java.lang.IllegalAccessException
protected java.lang.Object parseArray(java.lang.Class obj, java.lang.Class generic, java.lang.String data) throws ParserException, SourceFormatException, java.lang.InstantiationException, java.lang.IllegalAccessException
obj
- generic
- data
- ParserException
SourceFormatException
java.lang.InstantiationException
java.lang.IllegalAccessException