diff options
author | Leonid Startsev <sandwwraith@users.noreply.github.com> | 2022-10-27 18:45:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-27 18:45:16 +0300 |
commit | f451e43af7610d7e59a77c60c0e2bc9819c4997a (patch) | |
tree | 3547d85b7cb261d6c666b63804bdf1001f56f63c /formats/json-tests | |
parent | 16759876717d4682d10cf5d3c6d7bb9478c1c9e3 (diff) | |
download | kotlinx.serialization-f451e43af7610d7e59a77c60c0e2bc9819c4997a.tar.gz |
Remove experimentality from serializer(java.lang.Type) function family (#2069)
As it is needed for third-part converter libraries.
Revamp docs for all overloads of serializer().
Diffstat (limited to 'formats/json-tests')
-rw-r--r-- | formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt index 95b458c9..89e53a7a 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt @@ -102,6 +102,20 @@ class SerializersLookupTest : JsonTestBase() { } @Test + fun testStarProjectionsAreProhibited() { + val expectedMessage = "Star projections in type arguments are not allowed" + assertFailsWithMessage<IllegalArgumentException>(expectedMessage) { + serializer<Box<*>>() + } + assertFailsWithMessage<IllegalArgumentException>(expectedMessage) { + serializer(typeOf<Box<*>>()) + } + assertFailsWithMessage<IllegalArgumentException>(expectedMessage) { + serializerOrNull(typeOf<Box<*>>()) + } + } + + @Test fun testNullableTypes() { val myList: List<Int?> = listOf(1, null, 3) assertSerializedWithType("[1,null,3]", myList) @@ -121,6 +135,12 @@ class SerializersLookupTest : JsonTestBase() { } @Test + fun testLookupDuration() = noLegacyJs { + assertNotNull(serializerOrNull(typeOf<Duration>())) + assertSame(Duration.serializer(), serializer<Duration>()) + } + + @Test fun testCustomGeneric() = noLegacyJs { val intBox = Box(42) val intBoxSerializer = serializer<Box<Int>>() @@ -259,13 +279,6 @@ class SerializersLookupTest : JsonTestBase() { } } -// TODO uncomment when Kotlin 1.7.20 is released -// @Test -// fun testLookupDuration() = noLegacyJs { -// assertNotNull(serializerOrNull(typeOf<Duration>())) -// assertSame(Duration.serializer(), serializer<Duration>()) -// } - private inline fun <reified T> assertSerializedWithType( expected: String, value: T, |