You need to sign in to do that
Don't have an account?
Stefan Fellner
REST JSON 2 JAVA MAPPING
Hello,
I am creating a Android Application and I am using the Salesforce SDK.
As recommended I am using the REST API to get data from salesforce servers. All the examples indicate to hardcode the parameters to work with JSON Objects, for example to get the Id of a contact:
records.getJSONObject(i).getString("Id")
Is there any better way to avoid using the key of the json object as a string?
Normally I am using GSON library to parse the jsonObjects into my java objects. Are there java classes like Contact or Account available?
Thank you for your help!
Stefan
I am creating a Android Application and I am using the Salesforce SDK.
As recommended I am using the REST API to get data from salesforce servers. All the examples indicate to hardcode the parameters to work with JSON Objects, for example to get the Id of a contact:
records.getJSONObject(i).getString("Id")
Is there any better way to avoid using the key of the json object as a string?
Normally I am using GSON library to parse the jsonObjects into my java objects. Are there java classes like Contact or Account available?
Thank you for your help!
Stefan
contact and account.
https://developer.salesforce.com/page/Introduction_to_the_Force.com_Web_Services_Connector
if I have the WSC as a library in my project I would have a class like Contact.java but in the mechanism of SmartStore I am required to specify a key for all the attributes, like Id, Birthday, MobilePhone to be able to store and retrieve single contacts.
How would the WSC library solve this? Get the name of the field with something like this?
Field[] allFields = Contact.class.getFields();
allFields[0].getName();
Is this considered as the best practice? Does anyone has a better idea to handle the key issue on json objects?
Thanks
This Sample app uses the new wrappers in SmartSync library to simplify interaction with Salesforce objects. For example checkout this class: https://github.com/forcedotcom/SalesforceMobileSDK-Android/blob/master/native/SampleApps/SmartSyncExplorer/src/com/salesforce/samples/smartsyncexplorer/objects/ContactObject.java
Also, feel free to post your questions on our google+ community at: http://sfdc.co/mobilesdkcommunity
I think the solution you are providing is good, but on the long run creating those objects, such as "ContactObject" manually is not very robust in terms of changes to the API.
Are you going to deliver these classes as part of the SDK in future releases?
But why not shipping the standard objects with its attributes like you can get those from the salesforce workbench. And on top developers can customize these objects depending on their special needs.
An alternative would be to provide a Constant class with all the attributes names, so the usage of the same key in terms of Json objects can be guaranteed. In your example app "SmartSyncExplorer --> MainActivity" you use a hard coded string to store the Contact object attributes.