Converting a Response to a Data Model
Data models lets you define a representation of the data returned from a data source. The Akula client APIs define the AKBasicModel class ( Android / iOS ) that you can use to represent response data. By defining a model, you create a well-defined interface to access and manipulate the response data.
For more information on models and collections, see Modelling Data for Persistence.
Representing response data in a model
Data returned from a data source can take many forms. For example, the data can consist of a simple string, a JSON object, and array of JSON objects, binary data, or other types of data. One task of a client app is processing the response data returned from a data source. For example, the data might contain information used to populate a form. Or, the response data might contain an image displayed to the app user.
The Akula client APIs define the AKModel class that you can use to represent response data. By defining a model, you create a well-defined interface to access the response data.
Back-end data sources often correspond to a relational database or other type of structured data repository. Therefore, there is a strong correlation between a model and a back-end data source. That is, you typically define a model specific to the data source and make that model available to any client app that accesses the data source.
- On Android, AKModelUtil lets you convert a JSONObject to an AKModel object, convert a JSONArray to a List of AKModel objects, convert an AKModel object to a JSONObject, and convert an AKModel object to a Map.
- On iOS, AKModelUtil lets you convert an AKModel object to and from an NSDictionary object.
For example, if your Android app returns a JSON object in the response, you can use the AKModelUtil class to convert it to a model, as the following example shows: