fliptrip
(FlipTrip)
May 1, 2016, 2:55pm
1
This is how I save Group object which is added as relation in BackendlessUser table:
public static void createGroup(final String socialAccount) {
BackendlessUser user = Backendless.UserService.CurrentUser();
Group group = new Group();
group.setMembers("test member");
// TODO: test data!
group.setName((String) user.getProperty("firstName"));
group.setCoordinates(new GeoPoint(46.14, 14.45));
group.setPreferences("test preferences");
group.setLocation("test");
group.setVenues("venues test");
// end test data
user.setProperty("group", group);
Backendless.Persistence.save(user, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
Backendless.UserService.setCurrentUser(response);
Group group = (Group) response.getProperty("group");
String channel = CHANNEL_PREFIX + group.getObjectId();
registerPushNotifications(channel, socialAccount);
}@Override
public void handleFault(BackendlessFault fault) {
}
});
}
Now, when I run app in debug mode everything is saved as it should be (Group is created and all properties are populated with test data). Similar happens when the app is running in release mode except that the Group field members has null value (other fields are normally populated, see attached picture). Where could be the problem?
Could you check if the value for the “members” property is saved on the server?
fliptrip
(FlipTrip)
May 1, 2016, 4:48pm
3
Yes, I’ve also checked on the server and the expected value isn’t saved.
Could you show what the Group class looks like?
fliptrip
(FlipTrip)
May 1, 2016, 5:04pm
5
Sure, this is my current Group class:
public class Group implements Serializable {
private String ownerId;
private String venues;
private java.util.Date created;
private GeoPoint coordinates;
private java.util.Date updated;
private String location;
private String objectId;
private String preferences;
private String members;
private String name;
public String getOwnerId() {
return this.ownerId;
}
public String getVenues() {
return this.venues;
}
public java.util.Date getCreated() {
return this.created;
}
public GeoPoint getCoordinates() {
return this.coordinates;
}
public java.util.Date getUpdated() {
return this.updated;
}
public String getLocation() {
return this.location;
}
public String getObjectId() {
return this.objectId;
}
public String getPreferences() {
return this.preferences;
}
public String getMembers() {
return this.members;
}
public String getName() {
return this.name;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
public void setVenues(String venues) {
this.venues = venues;
}
public void setCreated(java.util.Date created) {
this.created = created;
}
public void setCoordinates(GeoPoint coordinates) {
this.coordinates = coordinates;
}
public void setUpdated(java.util.Date updated) {
this.updated = updated;
}
public void setLocation(String location) {
this.location = location;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
public void setPreferences(String preferences) {
this.preferences = preferences;
}
public void setMembers(String members) {
this.members = members;
}
public void setName(String name) {
this.name = name;
}
public Group save() {
return Backendless.Data.of(Group.class).save(this);
}
public Long remove() {
return Backendless.Data.of(Group.class).remove(this);
}
public static Group findById(String id) {
return Backendless.Data.of(Group.class).findById(id);
}
public static Group findFirst() {
return Backendless.Data.of(Group.class).findFirst();
}
public static Group findLast() {
return Backendless.Data.of(Group.class).findLast();
}
public static void fetchGroups() {
Backendless.Persistence.of(Group.class).find(new AsyncCallback<BackendlessCollection<Group>>() {
@Override
public void handleResponse(BackendlessCollection<Group> response) {
BusProvider.getInstance().post(new BackendlessCallbackEvent((ArrayList<Group>) response.getData()));
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
}
// region util
public int membersSize() {
Type type = new TypeToken<Set<String>>() {}.getType();
if (members != null && !members.isEmpty()) {
Set<String> users = new Gson().fromJson(members, type);
return users.size();
}
return 0;
}
public boolean isUserMemberOfGroup(String objectId) {
Type type = new TypeToken<Set<String>>() {}.getType();
if (members != null && !members.isEmpty()) {
Set<String> users = new Gson().fromJson(members, type);
return users.contains(objectId);
}
return false;
}
private Set<String> getMembersSet() {
try {
Type type = new TypeToken<Set<String>>() {
}.getType();
if (members != null && !members.isEmpty()) {
return new Gson().fromJson(members, type);
} else {
return new HashSet<String>();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void addMember(String member) {
Set<String> members = getMembersSet();
members.add(member);
this.members = new Gson().toJson(members);
}
public void removeMember(String userId) {
Set<String> members = getMembersSet();
members.remove(userId);
this.members = new Gson().toJson(members);
}
//endregion
}
But I’ve also tried with generated Group code from Backendless dashboard and same mistake happens.
Thanks. Could you please let me know your application id?
fliptrip
(FlipTrip)
May 1, 2016, 5:20pm
7
here it is: FCC97D67-C20B-7802-FFE0-E55CAC634000
fliptrip
(FlipTrip)
May 1, 2016, 5:33pm
8
Is the problem in my proguard file because I’m using it when I’m building the release variant of app:
#BACKENDLESS
-dontwarn com.backendless.**
-dontwarn weborb.**
-keep class weborb.** {*;}
-keep class com.backendless.** {*;}
fliptrip
(FlipTrip)
May 1, 2016, 6:47pm
9
I hope these screenshots would help. When I run the release variant of app then Group.getMembers isn’t in the array of methods which will be used for serialization, but in debug variant it is.
That is certainly the root cause of the problem. If the method is excluded, there is no way for Backendless to get the value.
fliptrip
(FlipTrip)
May 1, 2016, 9:18pm
11
I didn’t exclude this method as we can see from provided Group class.
The problem is somewhere with proguard/android compiler. I am at loss with what we (Backendless) could do here…
fliptrip
(FlipTrip)
May 1, 2016, 10:06pm
13
Okay, if I find the solution I’ll post it