|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.negro.jajb.JAJB
public final class JAJB
JAJB
is the main access point for binding between JSON
and Java Object.
It exposes 4 ways to realize binding:
1) You can use mapping way writing a configuration file for JAJB
and one or more mapping
files that describe all the entities you want to use; it's possible to describe converters, factories,
complex inheritance relations, specific constructors and other features for all the objects.
If you use this way, you can use the Collection types and array types as you want; you can have
the same features using the second way through the annotation configuration and SimpleJAJB class;
otherwise, if you use the third way, you can't use collection types, but only array types.
2) If you describe your beans using EntityAnnotation
and FieldAnnotation
, you will have all
configuration features (converters, factories, inheritance, etc.). Remember that if your bean
not have the EntityAnnotation, all of its FieldAnnotation will be ignored.
3) You can use JAJB
without mapping:
using this way you lose all the special features of the mapping way (conversions,
factories, etc.), but if json input structure is exactly equals respect to correspondent Java Bean and
you don't need the mapping way features, you can use this easier way.
If you don't use any mapping way , you can't use the Collection types, you must use the arrays.
4) You can use the three ways described before all together, combining xml mapping, annotated mapping and no mapping!
Remember that you cannot use Collection types for all of your not mapped bean!
Each bean can be referred by more ids and refIds:
1)For XML the ids must start with '$' and can continue as you want.
2) For annotation the ids must start with '@' and must continue with the correct full class name of the bean.
3) If you don't use any mapping the ids must start with '#' and must continue with the correct full class name of the bean.
Method Summary | |
---|---|
it.dangelo.domjson.JSON |
getJSON(java.io.File file)
Reads the passed parameter file and uses it to create a JSON object o array. |
it.dangelo.domjson.JSON |
getJSON(java.io.InputStream inputStream)
Reads the passed parameter inputStream content and uses it to create a JSON object o array. |
it.dangelo.domjson.JSON |
getJSON(java.io.Reader reader)
Reads the passed parameter reader content and uses it to create a JSON object o array. |
it.dangelo.domjson.JSON |
getJSON(java.lang.String jsonString)
Converts passed parameter jsonString into a JSON entity. |
java.lang.String |
marshall(java.lang.Object object)
Makes the same work of marshall (Object, String) method but considering the mapping runtime found: if class type of passed object parameter has an EntityAnnotation makes binding using its
annotated mapping, otherwise without any mapping. |
java.lang.String |
marshall(java.lang.Object object,
java.lang.String id)
This method serializes passed object parameter into a json string according to passed id parameter that represents the id of passed object into relative mapping file. |
java.lang.String |
marshallSimpleArray(java.lang.Object array)
Converts an array into a String representing a JSONArray . |
it.dangelo.domjson.JSONArray |
marshallSimpleArrayToJSONArray(java.lang.Object array)
Converts an array into a JSONArray . |
java.lang.String |
marshallSimpleCollection(java.util.Collection<?> collection,
java.lang.Class<?> componentType)
Converts a collection into a String representing a JSONArray . |
it.dangelo.domjson.JSONArray |
marshallSimpleCollectionToJSONArray(java.util.Collection<?> collection,
java.lang.Class<?> componentType)
Converts a collection into a JSONArray . |
it.dangelo.domjson.JSONElement |
marshallToJSONElement(java.util.Date date,
java.text.SimpleDateFormat simpleDateFormat)
Convert a Date into a JSONElement using passed SimpleDateFormat if not null,
otherwise using the default SimpleDateFormat (yyyy-MM-dd'T'HH:mm:ss'Z'ZZ); |
it.dangelo.domjson.JSONElement |
marshallToJSONElement(java.lang.Object object)
Makes the same work of marshallToJSONElement (Object, String) method but considering the mapping runtime found: if class type of passed object parameter has an EntityAnnotation makes binding using its
annotated mapping, otherwise without any mapping. |
it.dangelo.domjson.JSONElement |
marshallToJSONElement(java.lang.Object object,
java.lang.String id)
This method converts passed object parameter into a JSONElement according to passed id parameter that represents the id of passed object into relative mapping file or annotated id or simple mapping id. |
static JAJB |
newInstance()
This method returns a JAJB instance. |
static JAJB |
newInstance(java.io.InputStream inputStream)
This method returns a JAJB instance built parsing the configuration file located at the path specified by passed inputStream parameter. |
static JAJB |
newInstance(java.util.Properties properties)
Builds a new jajb instance configured with desired ProxyResolver class
you have to put into passed properties parameter. |
java.lang.Object |
unmarshall(it.dangelo.domjson.JSONElement jsonElement,
java.lang.Class<?> clazz)
Makes the same work of unmarshall(JSONElement, String) method but considering the mapping runtime found: if clazz has an EntityAnnotation makes binding using its annotated mapping, otherwise without
any mapping. |
java.lang.Object |
unmarshall(it.dangelo.domjson.JSONElement jsonElement,
java.lang.String id)
This method makes binding between passed jsonElement parameter and the specific java bean that you should have described in one of your mapping files with the id passed parameter. |
java.lang.Object |
unmarshall(java.lang.String jsonString,
java.lang.Class<?> clazz)
Makes the same work of unmarshall(String, String) method but considering the mapping runtime found: if clazz has an EntityAnnotation makes binding using its annotated mapping, otherwise without
any mapping. |
java.lang.Object |
unmarshall(java.lang.String jsonString,
java.lang.String id)
This method makes binding between passed jsonString parameter and the specific java bean that you should have described in one of your mapping files (be careful to instantiation method used to get JAJB instance) with the id passed parameter or with id of annotated bean (if it starts with '@') or with simple id (if it starts with '#'). |
java.lang.Object |
unmarshallSimpleArray(it.dangelo.domjson.JSONArray jsonArray,
java.lang.Class<?> arrayClass)
Converts a JSONArray into Java Array. |
java.lang.Object |
unmarshallSimpleArray(java.lang.String jsonArrayString,
java.lang.Class<?> arrayClass)
Converts a string representing a JSONArray into Java Array. |
java.util.Collection<?> |
unmarshallSimpleCollection(it.dangelo.domjson.JSONArray jsonArray,
java.lang.Class<?> collectionClass,
java.lang.Class<?> componentType)
Converts a JSONArray into a Collection of the specifies collectionClass
(for example ArrayList.class) containing specified componentType component. |
java.util.Collection<?> |
unmarshallSimpleCollection(java.lang.String jsonArrayString,
java.lang.Class<?> collectionClass,
java.lang.Class<?> componentType)
Converts a string representing a JSONArray into a Collection of the specifies collectionClass
(for example ArrayList.class) containing specified componentType component. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static JAJB newInstance(java.io.InputStream inputStream) throws JAJBException
inputStream
- an InputStream built with your JAJB configuration file.
JAJB
a JAJB instance with all mapping configuration informations initialized.
JAJBException
- this exception maybe caused by an IOException or SAXExcpetion (make sure of configuration file informations like path, sintax, etc.).public static JAJB newInstance() throws JAJBException
JAJB
a JAJB instance.
JAJBException
public static JAJB newInstance(java.util.Properties properties) throws JAJBException
ProxyResolver
class
you have to put into passed properties parameter.
You should put into properties a property with 'proxyResolver' like key
and with your desired ProxyResolver
implementation class name.
properties
- the properties in witch you should put the ProxyResolver
class name you want to use
JAJB
instance
JAJBException
public java.lang.Object unmarshall(java.lang.String jsonString, java.lang.String id) throws JAJBUnMarshallException
JSONArray
, you should pass into id parameter, the id of java bean
that are components of expected resulting array.
jsonString
- the json string that represents the java bean that you want to obtain invoking this method.id
- id of specific java bean.
JAJBUnMarshallException
public java.lang.Object unmarshall(java.lang.String jsonString, java.lang.Class<?> clazz) throws JAJBUnMarshallException
EntityAnnotation
makes binding using its annotated mapping, otherwise without
any mapping.
jsonString
- the json string that represents the java bean that you want to obtain as result.clazz
- the class type of the bean you want to obtain as result
JAJBUnMarshallException
public java.lang.Object unmarshall(it.dangelo.domjson.JSONElement jsonElement, java.lang.String id) throws JAJBUnMarshallException
jsonElement
- the JSONElement that represents the java bean that you want to obtain invoking this method.id
- id of specific java bean that you should have described in one of your mapping files
JAJBUnMarshallException
public java.lang.Object unmarshall(it.dangelo.domjson.JSONElement jsonElement, java.lang.Class<?> clazz) throws JAJBUnMarshallException
EntityAnnotation
makes binding using its annotated mapping, otherwise without
any mapping.
jsonElement
- the JSONElement that represents the java bean that you want to obtain invoking this method.clazz
- the class type of the bean you want to obtain as result
JAJBUnMarshallException
public java.lang.String marshall(java.lang.Object object, java.lang.String id) throws JAJBMarshallException
object
- the collection or array or java bean you want to serialize.id
- id of specific java bean that you should have described in one of your mapping files
JAJBMarshallException
public java.lang.String marshall(java.lang.Object object) throws JAJBMarshallException
EntityAnnotation
makes binding using its
annotated mapping, otherwise without any mapping.
object
- the collection or array or java bean you want to serialize.
JAJBMarshallException
public it.dangelo.domjson.JSONElement marshallToJSONElement(java.lang.Object object, java.lang.String id) throws JAJBMarshallException, JAJBException
object
- the collection or array or java bean you want to serialize.id
- id of specific java bean that you should have described in one of your mapping files
JAJBMarshallException
JAJBException
public it.dangelo.domjson.JSONElement marshallToJSONElement(java.util.Date date, java.text.SimpleDateFormat simpleDateFormat) throws JAJBMarshallException
Date
into a JSONElement
using passed SimpleDateFormat
if not null,
otherwise using the default SimpleDateFormat
(yyyy-MM-dd'T'HH:mm:ss'Z'ZZ);
date
- the date to convertsimpleDateFormat
- the format for conversion
JSONElement
representing passed date.
JAJBMarshallException
public it.dangelo.domjson.JSONElement marshallToJSONElement(java.lang.Object object) throws JAJBMarshallException
EntityAnnotation
makes binding using its
annotated mapping, otherwise without any mapping.
object
- the collection or array or java bean you want to serialize.id
- id of specific java bean that you should have described in one of your mapping files
JAJBMarshallException
public java.lang.Object unmarshallSimpleArray(java.lang.String jsonArrayString, java.lang.Class<?> arrayClass) throws JAJBUnMarshallException
JSONArray
into Java Array.
Use it only for simple component type (wrapper, primitive or Date
jsonArrayString
- the string to convert into Java ArrayarrayClass
- the array class for result
(for example 'int[].class', 'String[].class', etc.
JAJBUnMarshallException
public java.lang.Object unmarshallSimpleArray(it.dangelo.domjson.JSONArray jsonArray, java.lang.Class<?> arrayClass) throws JAJBUnMarshallException
JSONArray
into Java Array.
Use it only for simple component type (wrapper, primitive or Date
jsonArray
- the JSONArray
to convertarrayClass
- the array class for result
(for example 'int[].class', 'String[].class', etc.
JAJBUnMarshallException
public java.util.Collection<?> unmarshallSimpleCollection(java.lang.String jsonArrayString, java.lang.Class<?> collectionClass, java.lang.Class<?> componentType) throws JAJBUnMarshallException
JSONArray
into a Collection
of the specifies collectionClass
(for example ArrayList.class) containing specified componentType component.
jsonArayString
- the string to convertcollectionClass
- the collection class for result
(for example 'ArrayList.class', 'Vector.class', etc.componentType
- the class of collection component
JAJBUnMarshallException
public java.util.Collection<?> unmarshallSimpleCollection(it.dangelo.domjson.JSONArray jsonArray, java.lang.Class<?> collectionClass, java.lang.Class<?> componentType) throws JAJBUnMarshallException
JSONArray
into a Collection
of the specifies collectionClass
(for example ArrayList.class) containing specified componentType component.
jsonArray
- the JSONArray
to convertcollectionClass
- the collection class for result
(for example 'ArrayList.class', 'Vector.class', etc.componentType
- the class of collection component
JAJBUnMarshallException
public java.lang.String marshallSimpleArray(java.lang.Object array) throws JAJBMarshallException
JSONArray
.
Converts only Date[] or primitive array (int[], char[], etc) or wrapper array (String[], Boolean[], etc.)
array
- the array to convert
JSONArray
JAJBMarshallException
public it.dangelo.domjson.JSONArray marshallSimpleArrayToJSONArray(java.lang.Object array) throws JAJBMarshallException
JSONArray
.
Converts only Date[] or primitive array (int[], char[], etc) or wrapper array (String[], Boolean[], etc.)
array
- the array to convert
JSONArray
JAJBMarshallException
public java.lang.String marshallSimpleCollection(java.util.Collection<?> collection, java.lang.Class<?> componentType) throws JAJBMarshallException
JSONArray
.
Component type must be a wrapper type (String, Long, etc.) or a Date
collection
- componentType
-
JSONArray
JAJBMarshallException
public it.dangelo.domjson.JSONArray marshallSimpleCollectionToJSONArray(java.util.Collection<?> collection, java.lang.Class<?> componentType) throws JAJBMarshallException
JSONArray
.
Component type must be a wrapper type (String, Long, etc.) or a Date
collection
- componentType
-
JSONArray
JAJBMarshallException
public it.dangelo.domjson.JSON getJSON(java.lang.String jsonString) throws JAJBException
jsonString
-
JAJBException
public it.dangelo.domjson.JSON getJSON(java.io.File file) throws JAJBException
file
-
JAJBException
public it.dangelo.domjson.JSON getJSON(java.io.InputStream inputStream) throws JAJBException
inputStream
-
JAJBException
public it.dangelo.domjson.JSON getJSON(java.io.Reader reader) throws JAJBException
reader
-
JAJBException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |