Thread
#serialization
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    It would be so great to have some way of global discovery. I now have about 70 occurences in my project of `
    @Serializable(with = LocalDateSerializer::class)
    c

    crummy

    2 years ago
    I tried to fix that with this, with ktor:
    install(ContentNegotiation) {
            json(module = serializersModuleOf(LocalDate::class, LocalDateSerializer))
        }
    coulddn't get it to work though.
    bartvh

    bartvh

    2 years ago
    Would be great indeed, though I can imagine it's a complex subject to get exactly right (if there even is a definition of right that everybody can agree on). However, are you aware of https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/custom_serializers.md#useserializers-annotation ? This might alleviate some of your pain. I suppose it would help if Kotlin could also support annotations at the package or directory level.
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    The file annotation doesn't work with library classes and still reports an error. At runtime it works but the ide is filled with errors. And registering such a module would still need me to suppress the warnings
    bartvh

    bartvh

    2 years ago
    The linked paragraph specifically uses the library class
    java.util.Date
    as example, is it not working as intended? What kind of error do you get?
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    That's no library class
    bartvh

    bartvh

    2 years ago
    Then what do you mean by library class?
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    I.e. threeten LocalDate
    bartvh

    bartvh

    2 years ago
    But what is the error you get?
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    It doesn't work if the serializer is in another Gradle module
    "Serializer has not been found for type LocalDate..."
    bartvh

    bartvh

    2 years ago
    This compiles fine for me:
    @file:UseSerializers(HostAndPortSerializer::class)
    package x.y.z
    data class Endpoint(val hp: HostAndPort)
    HostAndPort
    being from Google Guava, and
    HostAndPortSerializer
    defined in another module. Using Kotlin 1.3.31.
    No IDEA warnings either, in 2020.1.1
    Oh wait I forgot the Serializable Still works
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    It compiles fine for me too, ist just full of ide warnings
    And your serializer is for sure in another module?
    bartvh

    bartvh

    2 years ago
    Yes, but it's not an Android project. I don't know too much about Android, but I believe the Gradle setup can get quite complex? Perhaps the IDE cannot handle it
    In any case, that's something for the serialization developers. I'm just another user. As far as I can see, you're using it correctly
    Paul Woitaschek

    Paul Woitaschek

    2 years ago
    Got it reproducible
    I'll report tomorrow with some additional ideas
    And I opened a feature request on suppressing warnings for specific classes through a compiler flag:https://github.com/Kotlin/kotlinx.serialization/issues/831