Rhoconnect Java Plugin JSONObject Issue

Using the rhoconnect java plugin, I did encountered major issue with the json conversion of objects. Using the JSONObject API, the plugin fails to handle properly nested objects/list/arrays/map/wrappers. It seems that the whole plugin uses JSONObject API extensively both in the two jar files. In our current Spring application, we are using Jackson ObjectMapper API and it pretty much excel in converting various objects and even inner classes and nested objects. Unlike JSONObject, it doesn't convert everything to String quoted element, especially arrays/list and nested object, I am hoping if I could request the rhoconnect team to fix this issue or better I suggest to switch from simple-json to jackson objectmapper api for json handling matters.

To provide a concrete scenario, for example a Map with these object

public class Form{

  Long id;

  List<Schedule> schedules;

  //getters and setters...

}

public class Schedule{

  private Timestamp startDate;

  private Timestamp endDate;

//getters and setters...

}

This will lead to json string converted by JSONObject

{

  "schedules" : "[

        {

           \"startDate\" : \"Feb 8, 2013 11:00 AM\",

           \"endDate\" : \"Feb 8, 2013 2:00 PM\"

        }

    ]",

  "id"  : "1108"

}

Which is wrong, the id value must stay as unquoted, and the array value for schedule must also be unquoted to be able to read properly by json parser as array. In the local database of the device, its hard to read such nested object without manually parsing the specific element of schedules and doing the dirty work arounds which is not scalable and fragile.

Hoping the rhoconnect team would consider this report, should i post this on github? Please tell me what to do?

And also, in our current Spring application, using ObjectMapper in doing the json transport on http did not give us any issues like this, so I think for rhoconnect API to be able to produce better JSON communication, ObjectMapper is the way to go, plus it is more popular and still improving.

John Michael Vi...
Finally, I still resorted to

Finally, I still resorted to using eval on converting stringified objects to ruby object. But I make sure using regex that a string is indeed a stringified array or object before calling eval on it to make sure it won't throw any exception. We won't be able to consider using source adapters since we already implemented rhoconnect java plugin and its much convenient to integrate and scalable. Thanks for the clarification about the limitation of rhoconnect server, much appreciated. I am just hoping in the future this could be fix.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexander Babichev
You are not quite correct,

You are not quite correct, when you think that plugin does not work with source adapters. Rhoconnect will use custom source adapter if it's available. Otherwise, it creates dynamic adapter and gives it to plugin. For example, this project https://github.com/rhomobile/rhoconnect-ffcrm

demonstrates usage of custom source adapter 'Account' with ruby plugin. Purpose of this adapter is to show how to query large data sets.  

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


John Michael Vi...
Alright, probably I did

Alright, probably I did misunderstand some of the statements in the docs and in the forums just like this post

https://developer.motorolasolutions.com/message/5905#5905

one of the comment says,

"Great!  Yes you don't want to have both a source adapter and plugin for the same model, RhoConnect will execute the adapter always if it exists."

In the docs in this link

http://docs.rhomobile.com/rhoconnect/plugin-intro

its says

"When you create a RhoConnect Plugin to connect your backend apps, you should not create a corresponding RhoConnect source adapter. RhoConnect Plugins do not use RhoConnect source adapters."

I could have misunderstood these statements, can you please help me out, I am confused.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexander Babichev
Doc statement is misleading:

Doc statement is misleading: it should say that  plugin eliminates needs to create a corresponding RhoConnect source adapter.. But it will use source adapter if it exists, and you need implement all CRUD functionality there. It might be useful if you want some extra features not provided by rhoconnect dynamic adapter.

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


John Michael Vi...
Thanks for clarification, now

Thanks for clarification, now I do understood it fully! It makes senses cause overriding the default source adapters should still allow you to utilize the plugins by connecting to its interface. Anyway I am really disappointed with the documentations, and I already have added this before in the my feedback when motorola emailed me a survey about this. Hope they fix these inconsistencies/inaccuracies of the documentations.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexander Babichev
Feel free post your report

Feel free post your report here: https://github.com/rhomobile/rhoconnect-java/issues

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


John Michael Vi...
Alright, already posted the

Alright, already posted the report. Eventually, my company agreed to fork the project and implement the changes to adopt ObjectMapper API instead of JSONObject. If we are able to accomplish this, we will upload the forked version as another branch for rhoconnect team to verify , accept and push to master branch.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


John Michael Vi...
After I had implemented

After I had implemented Jackson ObjectMapper API in replace of simple-json JSONObject API, still I get the same issue in the rhoconnect server data and rhomobile local database when syncing. Still the nested objects such as arrays, list, are still quoted unlike in normal http/ajax request which should not be.

This could mean the issue is in the rhoconnect server itself parsing the json data. For some reason, even the backend server is already pushing the better json string in the response, once it gets the rhoconnect server, via checking in the browser web console of rhoconnect, still the json data contains the double quote on the wrong elements.

The only work around that could be done in the side of rhomobile client app is to use eval to convert the stringified arrays/list/maps to the actual object. But I think using eval is quite dangerous just like sql injection. Also this workaround should be done explicitly to such model fields or worst iterate on each property and do the eval, this adds unnecessary complexity  of handling the models. Could anyone give me suggestions or explanation about this issue? Would be very much appreciated!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexander Babichev
Rhoconnect does not support

Rhoconnect does not support nested structures. All objects are presented as string attrib:value pairs. What you in web console, it's actually how they stored in redis. Your option is to create adapters for "Form" and "Schedure" objects respectively and tie both together in your rhodes mobile app.  

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


John Michael Vi...
We are using rhoconnect java

We are using rhoconnect java plugin in our backend server thus I believe we are not allowed to use source adapters, cause it won't allow rhoconnect to use both and always source adapter takes precedence whenever available, am i right?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments