How can I hide some fields from Backendless?

I have my class for table in Backendless

for example:

public class Table1() {
    public static final String FIELD_STATIC = "sdfsdf";
    private String field1;
    private String field2;
    private String field3;
}

I make:

Backendless.Data.of(Table1.class).save(table1);

In the result of this Backendless will create all columns from class Table1 in server (including static field!!!).

How can I say to Backendless ignore some fields? For example I want to ignore static fields and field2.
May be there are annotation for this?

Hi Timofey,

Private fields should be ignored. If columns are created for them, it must be a regression. We will check.

Public fields can be excluded by declaring then as “transient”.

If you have public getters and setters (Java bean style accessors) for a property, the property can be ignored with the following class-level annotation:

For example: the following class has public field “baz” and property “foo”. The annotation excludes the property “foo”:

@ExcludeProperty( propertyName = "foo" )
public class Bar
{
  public String baz;
  private String _foo;


  public String getFoo() 
  {
    return _foo;
  }


  public void setFoo( String value )
  {
    this._foo = value;
  }
}

The annotation can be imported with:
import weborb.service.ExcludeProperty;

Regards,
Mark

Thanks Mark! It is useful.

Could you please send me link to documentation about annotation? Maybe there is also functionality for using different name for class and table in Backendless for example?

It is an undocumented feature at the moment…

Yes, you can have different names between classes and table names. To map them, use the following API call right after you do Backendless.initApp:

Backendless.Persistence.mapTableToClass( String tableName, Class c );

Using the sample class from this thread you’d get:

Backendless.Persistence.mapTableToClass( “YourTableName”, Bar.class );

Regards,
Mark

I have a public transient static final field and it is being added to the table…

Sorry, I could not reproduce this problem. Here’s my class for the data object:

package com.mbaas;


public class Foo
{
  public transient static String STATICFIELD = "FooBar";
  public String name;
}

And here’s the code to save it in on the backend (the backend has no table for Foo at the time when i run the code). The code is just a command prompt program. If you use the same code in Android, make sure to use the asynchronous Backendless API:

package com.mbaas;


import com.backendless.Backendless;


public class SavingObjectWithTransientField
{
  public static void main( String[] args )
  {
    String APPLICATION_ID = "PUT-YOUR-APP-ID-HERE;
    final String SECRET_KEY = "PUT-YOUR-SECRET-KEY-HERE";
    Backendless.initApp( APPLICATION_ID, SECRET_KEY, "v1" );


    saveObject();
  }


  public static void saveObject()
  {
    Foo foo = new Foo();
    foo.name = "Chuck Norris";
    Backendless.Data.of( Foo.class ).save( foo );
  }
}

Once I run the code, Backendless created the following table. As you can see there is no column for the transient field “STATICFIELD”:
http://support.backendless.com/public/attachments/a2681d51e54bcb215c314228f016a104.png</img>

Hope this helps.

Mark