-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce InheritableSerialInfo and make JsonClassDiscriminator inher…
…itable
- Loading branch information
1 parent
7bc800b
commit 402be0c
Showing
8 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/commonTest/src/kotlinx/serialization/InheritableSerialInfoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kotlinx.serialization | ||
|
||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlin.test.* | ||
|
||
|
||
class InheritableSerialInfoTest { | ||
|
||
@InheritableSerialInfo | ||
annotation class InheritableDiscriminator(val discriminator: String) | ||
|
||
@InheritableDiscriminator("a") | ||
interface A | ||
|
||
@InheritableDiscriminator("a") | ||
interface B | ||
|
||
@InheritableDiscriminator("a") | ||
@Serializable | ||
abstract class C: A | ||
|
||
@Serializable | ||
sealed class D: C(), B | ||
|
||
@Serializable | ||
class E: D() | ||
|
||
@Serializable | ||
class E2: C() | ||
|
||
@Serializable | ||
class E3: A, B | ||
|
||
private fun doTest(descriptor: SerialDescriptor) { | ||
val list = descriptor.annotations.filterIsInstance<InheritableDiscriminator>() | ||
assertEquals(1, list.size) | ||
assertEquals("a", list.first().discriminator) | ||
} | ||
|
||
@Test | ||
fun testInheritanceFromSealed() = doTest(E.serializer().descriptor) | ||
@Test | ||
fun testInheritanceFromAbstract() = doTest(E2.serializer().descriptor) | ||
@Test | ||
fun testInheritanceFromInterface() = doTest(E3.serializer().descriptor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters