Repository: flutter
Issue: Support both primitives and Java wrapper classses like Booleans in StandardMessageCodec
Labels: c: new feature,platform-android,engine,P3,a: plugins,team-android,triaged-android

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill our the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!--
     Please tell us exactly how to reproduce the problem you are running into.

     Please attach a small application (ideally just one main.dart file) that
     reproduces the problem. You could use https://gist.github.com/ for this.

     If the problem is with your application's rendering, then please attach
     a screenshot and explain what the problem is.
-->

Hi, 

I recently ran into an interesting issue using Flutter and it's PlatformChannels.
**Background**: I use a Realm db (https://realm.io) to store an array of booleans on the native Android side. And I want to send these booleans to the Flutter side. Due to the Realm db those booleans are stored as type of **java.lang.Boolean** and not as type of Kotlin booleans. Actually the small difference shouldn't be a problem.

However, when the result (which is send to the Flutter channel) contains a boolean of type **java.lang.Boolean** an exception is thrown in...
**io.flutter.plugin.common.StandardMessageCodec.writeValue**

the interessing part of my code:

```dart
//returns the result which is send to the flutter side
fun convertToMap(question: Questions): HashMap<String, Any> {
    val dict: HashMap<String, Any> = hashMapOf<String, Any>(
            "history" to convertToBooleanArray(question.history)
    )
    return dict
}

//HELPER FUNCTION
fun convertToBooleanArray(boolList: RealmList<Boolean>): ArrayList<Boolean> {
    var newBoolList = arrayListOf<Boolean>()
    boolList.forEach {
        newBoolList.add(it) // **it** is type of java.lang.Boolean as shown in the Log.d
        Log.d("type of boolean:", it.javaClass.name)
        //current workaround is to compare the java.lang.Boolean to a Kotlin Boolean
        //something like this:
        //newBoolList.add(it==true) //the result of the comparison is of type boolean (kotlin) and this works!
    }
    return newBoolList
}
```

**further details:** 
Questions.history: RealmList<Boolean>

<!--
     Please tell us which target platform(s) the problem occurs (Android / iOS / Web / macOS / Linux / Windows)
     Which target OS version, for Web, browser, is the test system running?
     Does the problem occur on emulator/simulator as well as on physical devices?
-->

**Target Platform: Android**
**Target OS version/browser: 8 and 9 (probably all)**
**Devices: Samsung Galaxy S7/8/9 and all Pixel Emulators**


## Logs

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
D/type of boolean:( 9988): java.lang.Boolean
[  +18 ms] I/zygote64( 9988): Do partial code cache collection, code=61KB, data=42KB
[   +1 ms] I/zygote64( 9988): After code cache collection, code=61KB, data=42KB
[        ] I/zygote64( 9988): Increasing code cache capacity to 256KB
[  +50 ms] E/MethodChannel#skeleton/realm( 9988): Failed to handle method call
[        ] E/MethodChannel#skeleton/realm( 9988): java.lang.IllegalArgumentException: Unsupported value: true
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:283)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:283)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:57)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
[        ] E/MethodChannel#skeleton/realm( 9988):       at RealmService.getQuestionsWithIds(RealmService.kt:162)
[        ] E/MethodChannel#skeleton/realm( 9988):       at com.example.flutterskeleton.MainActivity$onCreate$1.onMethodCall(MainActivity.kt:33)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
[        ] E/MethodChannel#skeleton/realm( 9988):       at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
[        ] E/MethodChannel#skeleton/realm( 9988):       at android.os.MessageQueue.nativePollOnce(Native Method)
[        ] E/MethodChannel#skeleton/realm( 9988):       at android.os.MessageQueue.next(MessageQueue.java:325)
[        ] E/MethodChannel#skeleton/realm( 9988):       at android.os.Looper.loop(Looper.java:142)
[        ] E/MethodChannel#skeleton/realm( 9988):       at android.app.ActivityThread.main(ActivityThread.java:6944)
[        ] E/MethodChannel#skeleton/realm( 9988):       at java.lang.reflect.Method.invoke(Native Method)
[        ] E/MethodChannel#skeleton/realm( 9988):       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
[        ] E/MethodChannel#skeleton/realm( 9988):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
[  +49 ms] I/flutter ( 9988): PlatformException(error, Unsupported value: true, null)
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->
**flutter doctor -v:**
```
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.4 18E226, locale de-DE)
    • Flutter version 1.9.1+hotfix.6 at /Users/carlostrachwitz/Development/flutter
    • Framework revision 68587a0916 (9 weeks ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/carlostrachwitz/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.0, Build version 11A420a
    • CocoaPods version 1.8.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.40.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (2 available)
    • SM G930F                  • 9885e638394a4a3750 • android-arm64 • Android 8.0.0 (API 26)
    • Android SDK built for x86 • emulator-5554      • android-x86   • Android 6.0 (API 23) (emulator)

• No issues found!
```