jeggy
02/21/2023, 12:50 PMdata class MyDataClass(@IgnoreThisKey val privateKey: String, val value: String)
And when serializing any data(not only MyDataClass
) and there's a property with IgnoreThisKey
annotation, it should not be included.Derek Ellis
02/21/2023, 12:54 PM@Transient
is probably what you're looking forAdam S
02/21/2023, 1:34 PM@kotlinx.serialization.Transient
not
@kotlin.jvm.Transient
just in case you're not using IntelliJ, which will give this warning:
does not affect@kotlin.jvm.Transient
classes. Please use@Serializable
instead.@kotlinx.serialization.Transient
jeggy
02/21/2023, 1:42 PMAdam S
02/21/2023, 1:44 PM@Serializable
data class MyDataClass(
@Transient
val privateKey: String? = null,
val value: String,
)
Adam S
02/21/2023, 1:45 PMjeggy
02/21/2023, 1:47 PMjson.encodeToString(MyDataClass("private", "Value"))
it results in {"value": "Value"}
jeggy
02/21/2023, 1:54 PMjeggy
02/21/2023, 1:55 PMAdam S
02/21/2023, 1:56 PM@Transient
goes on propertiesAdam S
02/21/2023, 1:57 PM@SerialInfo
, which you can use on your custom annotations and they will be passed to the SerialDescriptor, but I don't think that's what you want https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serial-info/Adam S
02/21/2023, 1:59 PMvalue class Secret(val value: String)
so you can be sure that the value is never serialized?jeggy
02/21/2023, 2:03 PMAdam S
02/21/2023, 2:07 PM@Serializable(with = TransientSerializer::class)
data class MyDataClass(
val privateKey: String? = null,
val value: String,
)
object TransientSerializer : KSerializer<Any> {
override fun encode(...) {}
override fun decode(...) {}
}
jeggy
02/21/2023, 2:17 PMjeggy
02/21/2023, 2:17 PMAdam S
02/21/2023, 2:17 PM