SalomonBrys / Kotson

Kotlin bindings for JSON manipulation via Gson
MIT License
709 stars 37 forks source link

Nested generic type Issue #20

Closed brianyu0717 closed 7 years ago

brianyu0717 commented 7 years ago

Hi, just noticed an issue while using nested types e.g.

data class User(val id: String)

val a = gson.fromJson<List<List<User>>>("[\n" +
            "  [\n" +
            "    {\n" +
            "      \"id\": \"u-abcd\"\n" +
            "    }\n" +
            "  ]\n" +
            "]\n")

Expecting a to be of type ArrayList<ArrayList<User>>> however I'm getting ArrayList<ArrayList<LinkedTreeMap<etc... as per Gson>>> It looks like it's not getting past the 'first' level generic type.

SalomonBrys commented 7 years ago

This has to do with the fact that, in kotlin, List<T> is actually List<out T>, meaning it has declaration site variance.

This will be corrected in Kotson 2.5.0, thanks for the report ;)

SalomonBrys commented 7 years ago

Fixed in 2.5.0