BackendlessCollection in Business Logic returns inconsistent results

I have business logic in place that I use to perform searches in the cloud and return those results the client. The logic runs fine, and returns search results as a collection of Backendless users.

The problem is, some fields that are relationships to the User object do not return valid results.

Here is what my business code looks like:









	public static BackendlessCollection<BackendlessUser> getNewUsersByCity(String cityID) {

		Backendless.UserService.login(user, pass, true);

		String whereClause = "baseCity.objectId = '" + cityID + "'";

		BackendlessDataQuery dataQuery = new BackendlessDataQuery();

		dataQuery.setWhereClause( whereClause );

		QueryOptions queryOptions = new QueryOptions();

		queryOptions.addSortByOption( "created DESC" );

		dataQuery.setQueryOptions( queryOptions );

		BackendlessCollection<BackendlessUser> users = Backendless.Data.of( BackendlessUser.class ).find( dataQuery );

		return users;

	}

There is a field in my user table called “userType” which is a relationship to “UserType” table that simply contains the valid userTypes.

The problem is that for some users, the JSON comes back with a valid “userType” object and I can see the related data.

For other user records, in place of a userType, I get a single attribute call “___arrayref” which I have no Idea what to do with. The problem seems to persist on the same users each time. See attached screenshot of sample responses.

When you use Backendless API for Java, there is no JSON, the responses are automatically converted to Java objects.

In the code you referenced I see you do not load any related data. It is important to keep in mind that in Backendless related objects are not returned automatically, they need to be requested. Here’s the documentation that described how to retrieve relations in a query:
https://backendless.com/documentation/data/android/data_relations_retrieve.htm

Could you also clarify where that JSON comes from?

Regards,
Mark

Hi Mark,

The related data is set to auto-load. I’m able to get the correct data for some users as illustrated in the “Good Result” section of the image.

What you see in the screenshots is the returned JSON from the GET call to the API that gets generated after uploading my .jar file. I’m basically just retrieving user objects and all the related data along with it.

I see. Thank you for clarifying. The “arrayref” you’re seeing is an optimization we implemented to allow support for circular references. When an object (or an array) is referenced more than once in a response, it is serialized once, all other references to that object (or array) will be referenced through the special properties. Could you please post the entire JSON response, and I will help with an explanation for how to interpret those properties.

Regards,
Mark

Here you go. Notice the last 2 users, where the ‘UserType’ and ‘Experience’ don’t actually contain these respective objects.

File attached.

sample.rtf (29.9kB)

Any updates on this? See attached JSON response above.

It looks like maybe previously loaded objects are not duplicated. Instead a reference is given in the __meta property, and we must match the objectId found there with one of the objects already returned in the response. Is that accurate?

Hi,

Could you please export your data with relations and send to support@backendless.com with tag BKNDLSS-12074? We try to reproduce your issue.

Regards,

Denys

Hello - I sent this over. Any updates?

Hi,

We are currently working on this issue

Regards,

Denys

We cannot reproduce your issue with data you have provided and autoload on userType relation.
Try execute this query with relation depth 1.

queryOptions.setRelationsDepth( 1 );

Regards,

Denys

Thanks, but that didn’t help.

I just need to know how to interpret “___objectref” and “___arrayref” values so I can determine what to do with it. When I see these values, how do I get the actual object?

Hi everyone.

I found this issue. So.
I have 2 problems with this issue.

  1. Problem with REST server result. You can find an attach with REST call result. Please look through the 4th user and its experience field. It has:

“experience”: [
“1455309066000”,
“1459921012000”
],
This is incorrect values. You can find other bad values in other users and other fields.

  1. Problem with Java (Android) sdk. It handles wrong data in some “___objectref”'s. For example in field experience I can find object of my custom PortfolioImages class, but not custom Experience class. This is true not for all items as I can see.

bug.json.txt (36.75kB)

Internal task has been created for this issue.

Regards,

Denys

Hello - any updates?

The problem has been fixed and validated by QA. We will be deploying the changes to the production servers in the next few days.

Hi W,

We have updated our server, please download new CodeRunner using code generation Console > Business Logic > Service Events Handlers > Generated Code > Download.

Regards, Artur.

As I can see everything is fine.

Thank you!

Is this fix available in the standalone version?

Not yet.

Thanks for the reply. Is there a timeframe for it’s availability or a patch I can use in the meantime? We are on a rapid development schedule and this is a roadblock.