• diego-gomez-olvera

    diego-gomez-olvera

    2 years ago
    Hello everyone! I am experimenting with Protocol Buffers now https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/examples.md#user-defined-serial-annotations and I was wondering if it would be possible to get the schemas from
    @Serializable
    entities
    diego-gomez-olvera
    2 replies
    Copy to Clipboard
  • i

    Ivan Brko

    2 years ago
    Hi all, I have the following issue and I would be grateful if someone could point me in the right direction. I am using kotlinx.serialization in KMongo (org.litote.kmongo:kmongo-coroutine-serialization:3.12.2) I have the following data class which is in a file I cannot edit:
    data class User(
        val username: String,
        val email: String,
        val firstName: String,
        val lastName: String,
        val password: String,
        val role: Role,
        val createdAt: LocalDateTime,
        val updatedAt: LocalDateTime
    )
    So, in my file I create a serializer for it like this:
    @Serializer(forClass = User::class)
    object UserSerializer {}
    Now, everything seems to work OK when deserializing the data, however when KMongo tries to serialize it and send it to DB, I get a nasty java exception stack with the following message:
    java.lang.IndexOutOfBoundsException: com.example.domain.users.User descriptor has only 8 elements, index: 0
    After going through code, I found that in file PluginGeneratedSerialDescriptor.kt there is an overriden fun getElementDescriptor in which property generatedSerializer is trying to get accessed, but it is null and this causes the exception. Does anyone know if this is a bug, or I'm doing something wrong here?
    i
    Dominaezzz
    2 replies
    Copy to Clipboard
  • l

    Lamberto Basti

    2 years ago
    Hi! Say you have:
    @Serializable
    data class PagedData<T>(val data: T, val page: Int, val totalPages: Int, val pageSize: Int)
    Where you know for sure that
    T
    is a class that has the annotations
    @Serializable
    or a list of a type that is annotated with
    @Serializable
    . Why the serialization runtime is not able to infer what to use? Also, I am using Ktor, it would be kind of pointless to explicitly build a serializer before every response as such.
    l
    Dominaezzz
    9 replies
    Copy to Clipboard
  • altavir

    altavir

    2 years ago
    SerialDescriptor.withName is deprecated. What should I do not if I want to use a MapSerializer for another class. Should I leave the name as is?
    altavir
    Dominaezzz
    8 replies
    Copy to Clipboard
  • altavir

    altavir

    2 years ago
    Another question about map serialization. I have a map with polymorphic value type and I have serializer module for it. How can I construct a serializer for the map to use in custom serializer?
    altavir
    Dominaezzz
    3 replies
    Copy to Clipboard
  • altavir

    altavir

    2 years ago
    Another question (everything is working, but I want to make it more foolproof. I am serializing a double-linked tree (parent references children and children reference parent, so after deserialization I have to run a function to "attach" children to the partent. Currently I just use a serialization wrapper that does it after deserialization. Is there a better way? Some time ago I asked aboud after-deserialization-hooks and there were not any. Are there any changes?
    altavir
    turansky
    3 replies
    Copy to Clipboard
  • r

    rharter

    2 years ago
    I’m getting an 
    InvocationTargetException
     due to a 
    NoClassDefFoundError
     when trying to invoke the serializer() method on a 
    @Serializable
     class.  The class and method are found (via reflection using Ktor’s kotlinx.serialization content negotiation feature) and set accessible, but this still happens.  The annotated data class is public, but in a dependent module from the actual server that is executed. Any idea what might be wrong?
    r
    Sam Garfinkel
    +1
    28 replies
    Copy to Clipboard
  • f

    fkrauthan

    2 years ago
    Hey I am currently stuck trying to write a custom serializer. I pretty much get a JSON that contains a list of strings. But instead of having that list of strings (which are base64 encoded strings) I would like to write a serializer that takes in the string and decodes it before saving it in the internal data class
    f
    turansky
    2 replies
    Copy to Clipboard
  • SrSouza

    SrSouza

    2 years ago
    Hi folks, there is anyway to add a new annotation and use to map primitive types. Example:
    @Abs val num: Int
    =>
    {"num": -3}
    that deserialize to 3. I already create my owns annotation for Kotlinx.serialization, I know that supports it, but was for a new Enconder of mine, not from a existing one like Json.
    SrSouza
    Dominaezzz
    4 replies
    Copy to Clipboard
  • Sam Garfinkel

    Sam Garfinkel

    2 years ago
    Is there a way with reified generics to safely get a
    serializer
    from a generic
    T
    at compile-time? I know about
    KClass<T: Any>.serializer()
    but that relies on reflection. Likely doesn’t exist, but it would be cool to be able to mark a generic reified argument as
    @Serializable
    too (maybe limited to
    internal
    or
    private
    so that the constraint could be validated at compile time) so the compiler can validate it’s not used improperly and also to allow compile-time optimization of the inlined code to get the Serializer companion/object that’s available.
    Sam Garfinkel
    Kroppeb
    3 replies
    Copy to Clipboard