Package de.exlll.configlib
Interface SerializerContext
public interface SerializerContext
Instances of this class provide contextual information for custom serializers.
References to such instances can be obtained when adding serializer factories through
the
ConfigurationProperties.Builder.addSerializerFactory(Class, Function)
method.
Custom serializers used with @SerializeWith are allowed to declare a constructor
with one parameter of type SerializerContext. If such a constructor exists, a
context object is injected into it when the serializer is instantiated.
public final class PointSerializer implements Serializer<Point, String> {
private final SerializerContext context;
public PointSerializer(SerializerContext context) {
this.context = context;
}
// implementation ...
}
YamlConfigurationProperties properties = YamlConfigurationProperties.newBuilder()
.addSerializerFactory(Point.class, PointSerializer::new)
.build();
-
Method Summary
Modifier and TypeMethodDescriptionReturns theAnnotatedTypewhich led to the selection of the serializer.element()Returns theConfigurationElementfor which this serializer was selected.Returns theConfigurationPropertiesobject in use when the serializer was selected.
-
Method Details
-
properties
ConfigurationProperties properties()Returns theConfigurationPropertiesobject in use when the serializer was selected.- Returns:
- properties object in use when the serializer was selected
-
element
ConfigurationElement<?> element()Returns theConfigurationElementfor which this serializer was selected.- Returns:
- element for which this serializer was selected
-
annotatedType
AnnotatedType annotatedType()Returns theAnnotatedTypewhich led to the selection of the serializer. The annotated type returned by this method might be different from the one returned byConfigurationElement.annotatedType(). Specifically, the type is different when the serializer is applied to a nested type viaSerializeWithin which case the annotated type represents the type at that nesting level.- Returns:
- annotated type which led to the selection of the serializer
-