kotlinx.serialization
kotlinx.serialization copied to clipboard
fileSerializer not properly recognized by IntelliJ
I have a class that looks like this
@file:UseSerializers(BigDecimalSerializer::class, LocalDateSerializer::class)
@Serializable
data class MyRecordKeeper(val records: Map<LocalDate, BigDecimal>)
with
// FIXME
// compiler gives error when this class is not in business
// other serializers (BigDecimalSerializer) can stay in technical
// https://youtrack.jetbrains.com/issue/KT-44417
object LocalDateSerializer : KSerializer<LocalDate> {
override val descriptor = PrimitiveSerialDescriptor("LocalDate", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): LocalDate {
return LocalDate.parse(decoder.decodeString())
}
override fun serialize(encoder: Encoder, value: LocalDate) {
encoder.encodeString(value.toString())
}
}
and
object BigDecimalSerializer : KSerializer<BigDecimal> {
override val descriptor = PrimitiveSerialDescriptor("BigDecimal", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): BigDecimal {
return decoder.decodeString().toBigDecimal()
}
override fun serialize(encoder: Encoder, value: BigDecimal) {
encoder.encodeString(value.toPlainString())
}
}
for some reason I get the error:

Side notes & Qs:
- the serializers are in a different modules (imagine module1 "business", module2 "technical")
- to add to my confusion IntelliJ is giving me an error only for LocalDate and not for BigDecimal. But when I move the LocalDateSerializer to the
businessmodule, the error is gone. - conclusion: building the project works but its the editor that shows there is an error only for this one serializer. what can one do so that LocalDate is not underlined as error and future developers dont think there is something wrong?
Does error go away if you annotate LocalDate explicitly? Like Map<@Serializable(LocalDateSerializer::class) LocalDate, BigDecimal>?