Android Client SDK
com.verivo.akula.model.AKModelUtil Class Reference

The AKModelUtil class is a utility class which allows for the easy conversion of AKModel objects from one representation to another. More...

Static Public Member Functions

static< MextendsAKModel > M fromJSON (JSONObject obj, Class< M > type) throws InstantiationException, IllegalAccessException
 Convert a JSONObject into a model of the given type. More...
 
static< MextendsAKModel > List< M > fromJSON (JSONArray array, Class< M > type) throws JSONException, InstantiationException, IllegalAccessException
 Convert a JSONArray of JSONObjects into a list of models of the given type. More...
 
static< MextendsAKModel >
JSONObject 
toJSON (M model)
 Convert a model into a JSONObject. More...
 
static< MextendsAKModel > Map
< String, Object > 
toMap (M model)
 Retrieve the model's data values as a map. More...
 

Detailed Description

The AKModelUtil class is a utility class which allows for the easy conversion of AKModel objects from one representation to another.

Member Function Documentation

static <MextendsAKModel> M com.verivo.akula.model.AKModelUtil.fromJSON ( JSONObject  obj,
Class< M >  type 
) throws InstantiationException, IllegalAccessException
static

Convert a JSONObject into a model of the given type.

If the JSONObject contains properties which are themselves JSONObjects or JSONArrays, they will be ignored.

Parameters
objThe JSONObject to be converted into a model.
typeThe type of model to be created.
Returns
A model of the given type populated with the values from the given JSONObject.
Exceptions
InstantiationExceptionIf the given type does not have a null constructor or otherwise cannot be instantiated.
IllegalAccessException
Version
1.0
static <MextendsAKModel> List<M> com.verivo.akula.model.AKModelUtil.fromJSON ( JSONArray  array,
Class< M >  type 
) throws JSONException, InstantiationException, IllegalAccessException
static

Convert a JSONArray of JSONObjects into a list of models of the given type.

Parameters
arrayThe JSONArray to be converted into a model list.
typeThe type of models to be created.
Returns
A list of models of the given type populated with the values from the given JSONArray.
Exceptions
JSONExceptionIf the given JSONArray contains elements which are not JSONObjects.
InstantiationExceptionIf the given type does not have a null constructor or otherwise cannot be instantiated.
IllegalAccessException
Version
1.0
static <MextendsAKModel> JSONObject com.verivo.akula.model.AKModelUtil.toJSON ( model)
static

Convert a model into a JSONObject.

Parameters
modelThe model to be converted into a JSONObject.
Returns
A JSONObject containing the values from the given model.
Version
1.0
static <MextendsAKModel> Map<String, Object> com.verivo.akula.model.AKModelUtil.toMap ( model)
static

Retrieve the model's data values as a map.

Parameters
modelThe model from which to retrieve data.
Returns
A Map containing the data contained within the model, not including its local key.
Version
1.0