-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from avro-kotlin/removeSealedInterfaces
Remove sealed interfaces
- Loading branch information
Showing
17 changed files
with
183 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/github/avrokotlin/avro4k/SerializersModuleBuilder.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,43 @@ | ||
@file:OptIn(InternalSerializationApi::class) | ||
@file:Suppress("UNCHECKED_CAST") | ||
package com.github.avrokotlin.avro4k | ||
import kotlinx.serialization.InternalSerializationApi | ||
import kotlinx.serialization.modules.SerializersModuleBuilder | ||
import kotlinx.serialization.serializer | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Registers all direct subclasses of a sealed type as polymorphic types. | ||
* | ||
* Warning: This method will be removed with no further warning as soon as kotlinx.serialization natively supports | ||
* sealed interfaces. | ||
*/ | ||
fun <T : Any> SerializersModuleBuilder.polymorphicForSealed(sealedType: KClass<T>) { | ||
if (!sealedType.isSealed) throw IllegalArgumentException( | ||
"Type $sealedType is not sealed." | ||
) | ||
sealedType.sealedSubclasses.forEach { | ||
polymorphic(sealedType, it as KClass<T>, it.serializer()) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Registers all subclasses of a sealed type tree as polymorphic types. In contrast to polymorphicForSealed this method | ||
* also adds subclasses of sealed subclasses as polymorphic types. | ||
* | ||
* Warning: This method will be removed with no further warning as soon as kotlinx.serialization natively supports | ||
* sealed interfaces. | ||
*/ | ||
fun <T : Any> SerializersModuleBuilder.polymorphicTreeForSealed(sealedType: KClass<T>) { | ||
if (!sealedType.isSealed) throw IllegalArgumentException( | ||
"Type $sealedType is not a sealed type." | ||
) | ||
sealedType.sealedSubclasses.forEach { | ||
polymorphic(sealedType, it as KClass<T>, it.serializer()) | ||
if(it.isSealed) { | ||
polymorphicTreeForSealed(it) | ||
} | ||
} | ||
} | ||
|
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
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.