How to send Storage object as response in custom code

0 votes

I noticed on the tutorial for custom code that the response object is a JObject where we can put() values. I want to ask what's the preferred way to send an App42Response Object (User, Storage, etc.) as a JObject in custom-code (or if there's another way of sending it instead of as a JObject) and how I can Deserialize the response back to the desired App42Response class. I'm currently using Unity3D(C#) for my frontend, thanks.

I tried doing this, but i can't directly cast to Storage for example when I receive the response since the response is a JObject and not a Storage object:

 

              (part of custom-code snippet in Java):

@Override
public HttpResponseObject execute(HttpRequestObject request) {
...
 
Storage s = storageService.saveOrUpdateDocumentByKeyValue(...);
JSONObject js = null;
try {
js = new JSONObject(s);
} catch (JSONException e) {
e.printStackTrace();
}
 
return new HttpResponseObject(HTTP_STATUS_SUCCESS, js);
}
asked Mar 11, 2014 in App42 Cloud API-BaaS by jonathan.cortes (56 points)

1 Answer

0 votes
 
Best answer

If you want to cast response into Storage object, you have to send back storage response from custom code as JSONObject. Now on client side your JObject will contain Storage response inside. You can do following to cast it into Storage response

JObject customCodeResponse = // Response from Custom Code

Storage storage = new StorageResponseBuilder ().BuildResponse (customCodeResponse.ToString());

You have to put above code inside try catch block to handle non Storage response if it is expected from custom code.

answered Mar 11, 2014 by ajay123 (899 points)
selected Mar 11, 2014 by jonathan.cortes
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...