Im having a problem when sending a Cloud Code Request with parameters as a HashMap. The Funny thing is that if I send a request with empty parameters, it works perfectly fine. Here is my code for the request (Updated with ishmaelMakitla's answer) :
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", new String[]{"hey"});
ParseCloud.callFunctionInBackground("", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
@Override
public void done(Object object, ParseException e) {
Log.v("26", "" + object);
if (e != null) {
Log.v("27", "" + e);
}
for (Object obj : (ArrayList)object) {
Log.v("25",""+((ParseObject) obj).get("title"));
}
}
});
And my Cloud Code Method:
Parse.Cloud.define ('getFoo', function (req, res) {
var arrayIngredients = [];
arrayIngredients = req.params.ingredients;
var recepyQuery = new Parse.Query("Foos");
recepyQuery.find( {
success: function(result) {
res.success(result);
},
error: function() {
res.error("Nothing here");
}
});
});
This code works perfectly, but if i uncomment the par.put(...) part, it gives this error:
com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
This is my error stack:
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Looper.loop(Looper.java:146)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5653)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at dalvik.system.NativeStart.main(Native Method)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: Caused by: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:136)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:97)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCommand.<init>(ParseRESTCommand.java:138)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.<init>(ParseRESTCloudCommand.java:22)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.callFunctionCommand(ParseRESTCloudCommand.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloudCodeController.callFunctionInBackground(ParseCloudCodeController.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud$1.then(ParseCloud.java:64)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud$1.then(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:726)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$13.then(Task.java:818)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$13.then(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:690)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:796)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:830)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:99)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.starter.MainActivity.onCreate(MainActivity.java:62)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Activity.performCreate(Activity.java:5541)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.access$900(ActivityThread.java:172)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: ... 7 more
Is this a mistake I made or there is an issue with Parse? Im using Parse Server and Parse's Android SDK 1.13.0
Instead of passing the String[]
in the value, simply pass a String
, for this you should change your requesting code as follows -
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", "someIngredientValue"});
ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
//the rest of your code ...
On the receiving end, you then say request.params.ingredients
- this should give you 'someIngredientValue'.
I hope this helps.