ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.29k stars 1.01k forks source link

[Bug]: Android issues with sending Arrays in Capacitor Plugin #7747

Open biozal opened 3 weeks ago

biozal commented 3 weeks ago

Capacitor Version

Latest Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

Installed Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

[success] iOS looking great! 👌 [success] Android looking great! 👌

Other API Details

❯ npm --version
npm verbose cli /opt/homebrew/Cellar/node/22.8.0/bin/node /opt/homebrew/bin/npm
npm info using npm@10.8.2
npm info using node@v22.8.0
10.8.2
npm verbose cwd /Users/labeaaa/Developer/couchbase/cbl-ionic/example
npm verbose os Darwin 24.0.0
npm verbose node v22.8.0
npm verbose npm  v10.8.2
npm verbose exit 0
npm info ok

Platforms Affected

Current Behavior

When sending an Javascript nested array such as: const groups: any[] = []; groups.push(['a', 'b', 'c']); groups.push([1, 2, 3]);

If I push an object with this shape over the bridge, I get an error from the bridge before it calls the plugin method: JSONArray is not a valid type. Valid types are simple types and dictionaries and one-dimensional arrays of those types, including MutableDictionary, Dictionary, Map, MutableArray, Array, List, Blob, Date, String, Number, Boolean and null

This same object works just fine on iOS. On iOS I'm using Swift and on Android I'm using Kotlin.

Expected Behavior

I would expect that the nested array would serialize down to a JSONArray and be usable in my plugin. I've looked at passing over the information as a string and then serializing it and deserializing in Kotlin but this is a massive hit in performance when sending large JSON objects (our max is 20 MB in size) per object.

Project Reproduction

https://github.com/Couchbase-Ecosystem/cbl-ionic/example

Additional Information

This is for the new cbl-ionic plugin for Couchbase Mobile.