Jakub Pi
03/30/2020, 4:39 PM@Serializer(forClass = Map::class)
class MapWithLazyValue<K,V>(private val keySerializer : KSerializer<K>, private val valueSerializer : KSerializer<V>) : KSerializer<Map<K, Lazy<V>>> {
override val descriptor: SerialDescriptor = PrimitiveDescriptor("map", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): Map<K, Lazy<V>> {
return decoder.decodeSerializableValue(MapSerializer(keySerializer, valueSerializer)).mapValues { lazy { it.value } }
}
override fun serialize(encoder: Encoder, value: Map<K, Lazy<V>>) {
encoder.encodeSerializableValue(MapSerializer(keySerializer, valueSerializer),
value.filterValues { it.isInitialized() }.mapValues { it.value.value })
}
}
However, when I try to build my project, I get:
D:\IdeaProject\build\tmp\kapt3\stubs\main\com\collection\ArchiveHashCache.java:13: error: incompatible types: Class<MapWithLazyValue> cannot be converted to Class<? extends KSerializer<?>>
@kotlinx.serialization.Serializable(with = com.collection.MapWithLazyValue.class)
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: arrow.core.extensions.ExtensionProcessor (NON_INCREMENTAL), arrow.fold.AutoFoldProcessor (NON_INCREMENTAL), arrow.generic.CoproductProcessor (NON_INCREMENTAL), arrow.generic.ProductProcessor (NON_INCREMENTAL), arrow.higherkinds.HigherKindsProcessor (NON_INCREMENTAL), arrow.optics.OpticsProcessor (NON_INCREMENTAL).
I realize this may be a bug in kapt/arrow, but have I taken the right approach to writing my custom serializer or have I done something wrong?Jakub Pi
03/30/2020, 5:04 PM@Serializable(with=MapWithLazyValue::class) private var hashCache : MutableMap<FileKey, Lazy<String>> = ConcurrentHashMap<FileKey, Lazy<String>>()
Jakub Pi
03/30/2020, 5:47 PMclass MapWithLazyValue : LinkedHashMap<FileKey, Lazy<String>>()
and then implementing the serializer without any templates. Probably need to qualify my value type somehow, but IDE is not giving me any feedback.