How to add objects to BackendlessUser?

Hi guys, I can’t save NDevice and NDevice to BackendlessUser

BackendlessFault{ code: ‘IllegalArgumentException’, message: ‘java.lang.Object cannot be cast to java.util.Map’ }

I have next model:

public class NDevice {


    @SerializedName(Consts.ANDROID_ID)
    private String android_id;
    @SerializedName(Consts.GCM_TOKEN)
    private String gcm_token;
    @SerializedName(Consts.MODEL)
    private String model;
    @SerializedName(Consts.DIGIT_ID)
    private String digit_id;


}

Here I update users objects:

private static void updateFields(BackendlessUser user) {
    NDevice[] devices = devicesSet.toDevicesArray();
    NDevice device = NUser.i().device();


    user.setProperty(Consts.DEVICES, devices);
    user.setProperty(Consts.DEVICE, device);
}

save users data:

private void updateUser(BackendlessUser user) {


    if (user != null) {


        updateFields(user);


        Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>() {
            public void handleResponse(BackendlessUser user) {
                sendUserToFriendsAsync();
            }


            public void handleFault(BackendlessFault fault) {
                NoteMessage.showAlert("update fault", fault.toString());
            }
        });


    }
}

Application class:

Backendless.Data.mapTableToClass("NDevice", NDevice.class);
Backendless.initApp(this, Consts.BACKENDLESS_APP_ID, Consts.BACKENDLESS_SECRET_KEY, "v1");

Is it possible to update NDevice object if it already exists, without creating new one? I set android_id field as a unique in my backendless account.

The first problem might be happening because your model has no public fields or getter/setter methods.

As for updating NDevice if it already exists, it is possible. What you should do is populate the objectId property (or a public field) in the NDevice class. The property/field type must be String.

Mark

I replaced to public and still not working ((

public class NDevice implements Serializable{

 @SerializedName(Consts.ANDROID_ID)
 public String android_id;
 @SerializedName(Consts.GCM_TOKEN)
 public String gcm_token;
 @SerializedName(Consts.MODEL)
 public String model;
 @SerializedName(Consts.DIGIT_ID)
 public String digit_id;

 public String getAndroid_id() {
 return android_id;
 }

 public void setAndroid_id(String android_id) {
 this.android_id = android_id;
 }

 public String getGcm_token() {
 return gcm_token;
 }

 public void setGcm_token(String gcm_token) {
 this.gcm_token = gcm_token;
 }

 public String getModel() {
 return model;
 }

 public void setModel(String model) {
 this.model = model;
 }

 public String getDigit_id() {
 return digit_id;
 }

 public void setDigit_id(String digit_id) {
 this.digit_id = digit_id;
 }
}

This setProperty is working fine:
user.setProperty(Consts.DEVICE, NUser.i().device());

This is not working:
user.setProperty(Consts.DEVICES, devices);

I think the main problem that I can convert hashmap to NDevice[] array, but it’s not possible to convert from NDevice[] to hashmap fields and set them to BackendlessUser.
Can you please help?

Also when I try to update exists object NDevice related with BackendlessUser:

update fault: BackendlessFault{ code: ‘1155’, message: ‘Duplicate entry’ }

How to update exists object NDevice with unique field android_id?

Could you clarify what you meant by:

I think the main problem that I can convert hashmap to NDevice[] array, but it's not possible to convert from NDevice[] to hashmap fields and set them to BackendlessUser

The code you shared earlier assigns an array to a BackendlessUser object.

Regarding object update, please open a separate topic, it is hard to maintain two threads of questions within the same topic.