Custom Deserialiser
The Deserializer API depends on experimental APIs - see Configuration Nodes
To create a custom deserialiser, first, implement the deserialize method of the Deserializer interface.
class UUIDDeserializer implements Deserializer<UUID> {
@Override
public Renderer<UUID> deserialize(ConfigurationNode node, Deserializer.Context context) throws DeserializationException {
try {
return Renderer.of(UUID.fromString(node.asString());
} catch (IllegalArgumentException e) {
throw new DeserializationException(ConfigurationError.error("Must be a valid UUID"));
}
}
}class UUIDDeserializer : Deserializer<UUID> {
override fun deserialize(
node: ConfigurationNode,
context: Deserializer.Context
): Renderer<UUID> {
try {
return Renderer.of(UUID.fromString(node.asString());
} catch (e: IllegalArgumentException) {
throw DeserializationException(ConfigurationError.error("Must be a valid UUID"));
}
}
}Deserialisation Flow
The flow has three main stages:
Creation
Deserialisation
Rendering
Each stage helps to convert some part of the input configuration into the final value returned by a given @Property method.
The initial stage, creation, is completely internal, however you may still see it when you create methods of the return type List<E> where E cannot be deserialised. This will prevent your configuration object from being created before any deserialisation starts.
Next comes the deserialisation stage. This is called once, when your configuration object is built. This usually involves "processing" of the given node which may include validation or even arriving at a value. Once the input has been processed, the deserialiser returns a Renderer object which is a function that is called during the rendering stage.
The rendering stage is the final stage and may occur several times throughout the lifetime of your configuration object. Rendering occurs whenever a @Property method is called. Here you must return a value. You however may choose to do some final processing such as creating a defensive copy or transforming the value.
Last updated