-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
63 additions
and
10 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
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/github/avrokotlin/avro4k/internal/LogicalTypesSerializersCollector.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,45 @@ | ||
package com.github.avrokotlin.avro4k.internal | ||
|
||
import com.github.avrokotlin.avro4k.AvroConfiguration | ||
import com.github.avrokotlin.avro4k.serializer.AvroSchemaSupplier | ||
import com.github.avrokotlin.avro4k.serializer.ElementLocation | ||
import com.github.avrokotlin.avro4k.serializer.SchemaSupplierContext | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.SerializationStrategy | ||
import kotlinx.serialization.modules.SerializersModuleCollector | ||
import kotlin.reflect.KClass | ||
|
||
internal class LogicalTypesSerializersCollector( | ||
private val configuration: AvroConfiguration, | ||
) : SerializersModuleCollector { | ||
internal var serializers: MutableMap<String, KSerializer<Any>> = mutableMapOf() | ||
|
||
override fun <T : Any> contextual(kClass: KClass<T>, serializer: KSerializer<T>) { | ||
if (serializer !is AvroSchemaSupplier || serializer.descriptor.isNullable) { | ||
return | ||
} | ||
val schema = runCatching { serializer.getSchema(SimpleContext(configuration)) }.getOrNull() | ||
if (schema?.logicalType != null) { | ||
@Suppress("UNCHECKED_CAST") | ||
serializers[schema.logicalType.name] = serializer as KSerializer<Any> | ||
} | ||
} | ||
|
||
override fun <T : Any> contextual(kClass: KClass<T>, provider: (typeArgumentsSerializers: List<KSerializer<*>>) -> KSerializer<*>) { | ||
} | ||
|
||
override fun <Base : Any, Sub : Base> polymorphic(baseClass: KClass<Base>, actualClass: KClass<Sub>, actualSerializer: KSerializer<Sub>) { | ||
} | ||
|
||
override fun <Base : Any> polymorphicDefaultDeserializer(baseClass: KClass<Base>, defaultDeserializerProvider: (className: String?) -> DeserializationStrategy<Base>?) { | ||
} | ||
|
||
override fun <Base : Any> polymorphicDefaultSerializer(baseClass: KClass<Base>, defaultSerializerProvider: (value: Base) -> SerializationStrategy<Base>?) { | ||
} | ||
} | ||
|
||
private class SimpleContext( | ||
override val configuration: AvroConfiguration, | ||
override val inlinedElements: List<ElementLocation> = emptyList(), | ||
) : SchemaSupplierContext |
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