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
callFunctionInBackgroundto not use Generic type (Object) and instead usingParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback(){...}- give it a try and let me know if this helps.donemethods? Maybe update your code with the latest code you've got. Also what happens if yourHashMapexplicitly uses string array for value type (instead ofObject)?result? Could you print the log of yourresultjust beforeres.success(result);- I am wondering if the error has to be with the parameters you send or the response.