Global Component Data Serializer
Serializes and deserializes data from parameters annotated with @SerializableComponentData and @SerializableTimeoutData.
Default implementation
By default, a Jackson-based serializer with the Kotlin module is used.
Overriding the default instance
You can override the default instance by creating a service implementing this interface, in which you can use any serialization library you want.
Tip: You will generally need to get the type of the to-be-deserialized parameter, which you can get from the ParameterWrapper.
Here's an example with kotlinx.serialization:
@BService
class KotlinxComponentDataSerializer : GlobalComponentDataSerializer {
// Default instance, you can customize it later
private val json = Json
override fun deserialize(parameter: ParameterWrapper, data: SerializedComponentData): Any {
return json.decodeFromString(serializer(parameter.type), data.asString())!!
}
override fun serialize(parameter: ParameterWrapper, obj: Any): SerializedComponentData {
val json = json.encodeToString(serializer(parameter.type), obj)
return SerializedComponentData.fromString(json)
}
}
Content copied to clipboard
Functions
Link copied to clipboard
Link copied to clipboard
Serializes the given object into a SerializedComponentData.