Support Topics Documentation Slack YouTube Blog

Mapping Database Tables/columns and client objects similar to Parse key/value pairs

I have a need to migrate my Parse application written for
the Android platform to another MBaaS service and I had a question.

Currently the Parse applications that I want to migrate
utilize the ability to remap class names and property names without having to
rebuild the client application. This is
done using a generic object (ParseObject) hash table where the key is the
column name along with the value for the column.

I have multiple common java class files that I use to
interface with the Parse service and these classes are used in multiple
applications. In addition, I am using
reflection to load the Parse.jar file at runtime as well as other 3rd
party libraries.

I see that the Backendless SDK currently provides the
MapToTable function (i.e. object.MapToTable(“TableName”) which is very good
since it allows me to easily map this table name given a different
configuration variable name. I also see
the use of the annotations statement MapToProperty(…) which provides the
variable mapping of property names that correspond to the table column name in
Backendless. This works well for
statically loading the Backendless.jar file but when I use it with reflection,
it doesn’t work.

I am currently trying to generate a quick Android
application using reflection that gives me the same functionality of the
key/value pair processing that Parse provides.
I don’t see a current method in the Backendless Android SDK that
provides the developer to map different column names.

Can additional functionality be added to support the
key/value mapping between ParseObjects and the Database schema Tables and columns, that my current applications utilizes?

With Backendless you can customize mapping of tables to custom classes through an API call:

Backendless.Data.mapTableToClass( "tableName", FooBar.class )

This will create table People with columns “name” and “age” and store the object in there.

If you were to use custom Java classes and will have a need to define custom mapping between columns and java fields/properties, that will not work very well with reflection. The reason for this is we use annotation to create such a mapping.

As an alternative, you can use communicate with the backend without any custom classes at all. For example:

HashMap myObject = new HashMap();
myObject.put( "name", "Joe" );
myOBject.put( "age", 21 );
Backendless.Data.of( "People" ).save( myObject );