Data Object¶
Backendless database stores objects in data tables. A persisted object is stored in a language-independent format. For the Android and Java applications, there are two ways to represent data objects on the client side:
- Data objects can be stored/retrieved as instances of
java.util.Map
. For example, the following code saves an object with properties"name"
and"age"
in the"Person"
table:This approach is referenced as "Java Map" further in the documentation.HashMap person = new HashMap(); person.put( "name", "Joe" ); person.put( "age", 25 ); Backendless.Data.of( "Person" ).save( person );
or - Data objects can be represented as instances of custom classes mapped to data tables. Object's class does not need to implement any special Backendless interfaces or extend a class from the Backendless SDK. For example, the following code saves an object with properties
"name"
and"age"
in the"Person"
table:This approach is referenced as "Custom Class" further in the documentation.public class Person { // using public fields, but you can // use getter/setter methods too public String name; public int age; } Person person = new Person(); person.name = "Joe"; person.age = 25; Backendless.Data.of( Person.class ).save( person );
There are several requirements imposed on the classes of the objects saved in the Backendless database:
- The class must contain the default, public, no-argument constructor.
- The class must contain either at least one public field or a pair of getter and setter methods conforming to the Java Bean naming convention.
-
Optional requirement - Backendless automatically assigns a unique ID to every persisted object. If the application needs to have access to the assigned ID, the class must declare the following field:
public String objectId;
-
Optional requirement - in addition to
objectId
, Backendless maintains two other properties for every persisted object -created
andupdated
. The former contains the timestamp when the object was initially created in the Backendless database. The latter is updated every time the object is updated. To get access to these values, the class must declare the following fields:public Date created; public Date updated;