Describe the bug
Out BE is sending array of objects in response. While plugin is processing response it trow this error in Android Studio console
2020-06-23 11:31:15.059 14364-14445/com.my.app E/Capacitor/Plugin: Error org.json.JSONException: Not a primitive array: class java.lang.String at org.json.JSONArray.<init>(JSONArray.java:118) at com.getcapacitor.JSArray.<init>(JSArray.java:21) at com.getcapacitor.plugin.http.Http.buildResponse(Http.java:395) at com.getcapacitor.plugin.http.Http.get(Http.java:83) at com.getcapacitor.plugin.http.Http.request(Http.java:64) at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) at com.getcapacitor.Bridge$1.run(Bridge.java:520) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.os.HandlerThread.run(HandlerThread.java:67)
To Reproduce
Try to get array of objects from server
Smartphone:
Device: Pixel 3 (Virtualized)
OS: Android 10
Additional context
Example response from BE
[ { "id": "XXXXX", "name": "xxxx", "info": "xyz", "available-from": "2020-05-01" }, { "id": "YYYY", "name": "yyyyy", "info": "yzx", "available-from": "2020-05-01" } ]
Error appears to be in Http.java. While plugins is trying to buildResponse that should be send back to "webview".
JSArray jsonValue = new JSArray(builder.toString());
We made a quick fix just as POC. Basically we just wrapped array in object and parse it like that.
//JSArray jsonValue = new JSArray(builder.toString());
JSObject jsonValue = new JSObject("{\"_CAPACITOR_FIX_ARRAY\": " + builder+ "}");
ret.put("data", jsonValue);
Describe the bug Out BE is sending array of objects in response. While plugin is processing response it trow this error in Android Studio console
2020-06-23 11:31:15.059 14364-14445/com.my.app E/Capacitor/Plugin: Error org.json.JSONException: Not a primitive array: class java.lang.String at org.json.JSONArray.<init>(JSONArray.java:118) at com.getcapacitor.JSArray.<init>(JSArray.java:21) at com.getcapacitor.plugin.http.Http.buildResponse(Http.java:395) at com.getcapacitor.plugin.http.Http.get(Http.java:83) at com.getcapacitor.plugin.http.Http.request(Http.java:64) at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) at com.getcapacitor.Bridge$1.run(Bridge.java:520) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.os.HandlerThread.run(HandlerThread.java:67)
To Reproduce
Smartphone:
Additional context Example response from BE
[ { "id": "XXXXX", "name": "xxxx", "info": "xyz", "available-from": "2020-05-01" }, { "id": "YYYY", "name": "yyyyy", "info": "yzx", "available-from": "2020-05-01" } ]
Error appears to be in Http.java. While plugins is trying to buildResponse that should be send back to "webview".
JSArray jsonValue = new JSArray(builder.toString());
We made a quick fix just as POC. Basically we just wrapped array in object and parse it like that.