Backendless Support
 

Custom mapping between Data tables and Client classes

The article  "The Client Class to Data Table Mapping" explains how the data tables in the Backendless map to the client-side classes whose instances contain persisted data objects. However, there are scenarios when the default mapping is undesirable. In that case, the Backendless client libraries provide an API to override the mapping.

For example, consider the following data table (Restaurant):

Suppose that for some reason the client-side class for the objects in the Restaurant table must be called PlaceToEat. The mapping between the Restaurant table and the PlaceToEat class can be established using the following API:

Backendless.Data.mapTableToClass( "Restaurant", PlaceToEat.class );

Where the  PlaceToEat class has the following structure (class's fields and properties must match the table columns):

JAVA

import com.backendless.BackendlessUser;
public class PlaceToEat
{
 private String name;
 private String objectId;
 private String cuisine;
 private java.util.List<Location> locations;
 private BackendlessUser owner;
 // skipping getters and setters for brevity
}

OBJECTIVE-C

//
// PlaceToEat.m
// F123CustomClassToTableMapping
#import "PlaceToEat.h"
@implementation PlaceToEat
@end

SWIFT

import Foundation
 
class PlaceToEat : NSObject {
 
 var name : String?
 var objectId : String?
 var cuisine : String?
 var locations : [Location]?
 var owner : BackendlessUser?
}

It is recommended that mapTableToClass method is called right after the initApp method, that is before any other API which fetches data from the server.

Is article helpful?