Repository: kotlin/kotlinx.serialization
Issue: A compiler-generated serializer for a Collection property works, serializer<Collection<…>>() does not

**Describe the bug**

- A property of type `Collection<String>` is serialized as `[ … ]`.
- Serializing a value of type `Collection<String>` using `serializer<Collection<String>>()` fails with an error.

**To Reproduce**
```kt
@Serializable
class Foo(val value: Collection<String>)

fun main() {
    val foo = Foo(listOf("foo"))
    val bar: Collection<String> = listOf("bar")

    println(Json.encodeToString(foo)) // outputs {"value":["foo"]}
    println(Json.encodeToString(bar)) // Class 'SingletonList' is not registered for polymorphic serialization in the scope of 'Collection'.
}
```

**Expected behavior**
`Collection` should consistently be serialized as a list, independent of the actual implementation of `Collection`.

Should output:
```
{"value":["foo"]}
["bar"]
```

**Environment**
 - Kotlin version: 1.4.21
 - Library version: 1.0.1
 - Kotlin platforms: JVM
 - Gradle version: 6.5.1

Changed files:
formats/json/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt
core/commonMain/src/kotlinx/serialization/Serializers.kt
formats/json/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
core/jvmMain/src/kotlinx/serialization/SerializersJvm.kt

diff --git a/core/commonMain/src/kotlinx/serialization/Serializers.kt b/core/commonMain/src/kotlinx/serialization/Serializers.kt
index 4087c884..cae088de 100644
--- a/core/commonMain/src/kotlinx/serialization/Serializers.kt
+++ b/core/commonMain/src/kotlinx/serialization/Serializers.kt
@@ -79,7 +79,7 @@ private fun SerializersModule.builtinSerializerOrNull(
         .map(::serializer)
     // Array is not supported, see KT-32839
     return when (rootClass) {
-        List::class, MutableList::class, ArrayList::class -> ArrayListSerializer(serializers[0])
+        Collection::class, List::class, MutableList::class, ArrayList::class -> ArrayListSerializer(serializers[0])
         HashSet::class -> HashSetSerializer(serializers[0])
         Set::class, MutableSet::class, LinkedHashSet::class -> LinkedHashSetSerializer(serializers[0])
         HashMap::class -> HashMapSerializer(serializers[0], serializers[1])
diff --git a/core/jvmMain/src/kotlinx/serialization/SerializersJvm.kt b/core/jvmMain/src/kotlinx/serialization/SerializersJvm.kt
index 83d9b92a..901e633d 100644
--- a/core/jvmMain/src/kotlinx/serialization/SerializersJvm.kt
+++ b/core/jvmMain/src/kotlinx/serialization/SerializersJvm.kt
@@ -47,8 +47,8 @@ public fun SerializersModule.serializer(type: Type): KSerializer<Any> = when (ty
         val rootClass = (type.rawType as Class<*>)
         val args = (type.actualTypeArguments)
         when {
-            List::class.java.isAssignableFrom(rootClass) -> ListSerializer(serializer(args[0])) as KSerializer<Any>
             Set::class.java.isAssignableFrom(rootClass) -> SetSerializer(serializer(args[0])) as KSerializer<Any>
+            List::class.java.isAssignableFrom(rootClass) || Collection::class.java.isAssignableFrom(rootClass) -> ListSerializer(serializer(args[0])) as KSerializer<Any>
             Map::class.java.isAssignableFrom(rootClass) -> MapSerializer(
                 serializer(args[0]),
                 serializer(args[1])
diff --git a/formats/json/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt b/formats/json/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt
index f447b7d4..c40d8f9f 100644
--- a/formats/json/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt
+++ b/formats/json/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt
@@ -6,9 +6,7 @@ package kotlinx.serialization
 
 import kotlinx.serialization.builtins.*
 import kotlinx.serialization.descriptors.*
-import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
 import kotlinx.serialization.encoding.*
-import kotlinx.serialization.internal.*
 import kotlinx.serialization.json.*
 import kotlinx.serialization.modules.*
 import kotlinx.serialization.test.*
@@ -45,6 +43,13 @@ class SerializersLookupTest : JsonTestBase() {
         assertSerializedWithType("""["a","b","c"]""", myArr)
     }
 
+    @Test
+    fun testListAsCollection() {
+        val myArr: Collection<String> = listOf("a", "b", "c")
+        assertSerializedWithType("""["a","b","c"]""", myArr)
+    }
+
+
     @Test
     fun testPrimitiveSet() {
         val mySet = setOf("a", "b", "c", "c")
diff --git a/formats/json/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt b/formats/json/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
index 46162e09..b29c6694 100644
--- a/formats/json/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
+++ b/formats/json/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
@@ -78,6 +78,19 @@ class SerializerByTypeTest {
         assertEquals("""["a","b","c"]""", s)
     }
 
+    @Test
+    fun testListAsCollection() {
+        val myArr: Collection<String> = listOf("a", "b", "c")
+        val token = object : ParameterizedType {
+            override fun getRawType(): Type = Collection::class.java
+            override fun getOwnerType(): Type? = null
+            override fun getActualTypeArguments(): Array<Type> = arrayOf(String::class.java)
+        }
+        val serial = serializer(token)
+        val s = json.encodeToString(serial, myArr)
+        assertEquals("""["a","b","c"]""", s)
+    }
+
 
     @Test
     fun testReifiedArrayResolving() {