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 Details

    • properties

      Returns the ConfigurationProperties object in use when the serializer was selected.
      Returns:
      properties object in use when the serializer was selected
    • element

      ConfigurationElement<?> element()
      Returns the ConfigurationElement for which this serializer was selected.
      Returns:
      element for which this serializer was selected
    • annotatedType

      AnnotatedType annotatedType()
      Returns the AnnotatedType which led to the selection of the serializer. The annotated type returned by this method might be different from the one returned by ConfigurationElement.annotatedType(). Specifically, the type is different when the serializer is applied to a nested type via SerializeWith in which case the annotated type represents the type at that nesting level.
      Returns:
      annotated type which led to the selection of the serializer