-
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 @JsonClassDiscriminator to confi…
…gure discriminator per polymorphic base class Fixes #546
- Loading branch information
1 parent
63eff4d
commit be7af57
Showing
19 changed files
with
398 additions
and
106 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
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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
package kotlinx.serialization | ||
|
||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.test.isJsLegacy | ||
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) { | ||
if (isJsLegacy()) return // Unsupported | ||
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
Oops, something went wrong.