Thread
#serialization
    bartvh

    bartvh

    3 years ago
    I want to serialize a set of IP addresses. I have created an InetAddressSerializer, but how do I apply it to a set using annotations? I can't use
    (..).set
    in an annotiation.
    @Serializable
    data class SessionState(
            @Serializable(with = InstantSerializer::class)
            val start: Instant,
            val ips: Set<InetAddress>?
    )
    Ok, I've solved it like this now:
    object InetAddressSetSerializer : KSerializer<Set<InetAddress>> by InetAddressSerializer.set
    
    @Serializable(with = InetAddressSetSerializer::class)
    but it doesn't seem desirable to me to do it like this every time a collection needs to be serialized