Package de.bild.codec

Interface PolymorphicCodec<T>

Type Parameters:
T - the value type
All Superinterfaces:
org.bson.codecs.Codec<T>, org.bson.codecs.Decoder<T>, org.bson.codecs.Encoder<T>, TypeCodec<T>
All Known Subinterfaces:
ReflectionCodec<T>
All Known Implementing Classes:
BasicReflectionCodec

public interface PolymorphicCodec<T> extends TypeCodec<T>
Provides functionality for handling polymorphic structures. decode() as well as encode() have default implementations within this interface.

Attention: The name of this interface may be misleading. Any Codec that might be part of a polymorphic codec structure needs to implement this interface, as the codec needs to answer certain questions, most obviously verifyFieldsNotNamedLikeAnyDiscriminatorKey(java.util.Set<java.lang.String>) A map of PolymorphicCodec is part of PolymorphicReflectionCodec which itself does not implement PolymorphicCodec

  • Field Details

    • LOGGER

      static final org.slf4j.Logger LOGGER
  • Method Details

    • decodeFields

      T decodeFields(org.bson.BsonReader reader, org.bson.codecs.DecoderContext decoderContext, T instance)
    • encodeFields

      void encodeFields(org.bson.BsonWriter writer, T instance, org.bson.codecs.EncoderContext encoderContext)
    • newInstance

      T newInstance()
    • decode

      default T decode(org.bson.BsonReader reader, org.bson.codecs.DecoderContext decoderContext)
      Specified by:
      decode in interface org.bson.codecs.Decoder<T>
    • encode

      default void encode(org.bson.BsonWriter writer, T value, org.bson.codecs.EncoderContext encoderContext)
      Specified by:
      encode in interface org.bson.codecs.Encoder<T>
    • verifyFieldsNotNamedLikeAnyDiscriminatorKey

      void verifyFieldsNotNamedLikeAnyDiscriminatorKey(Set<String> discriminatorKeys) throws IllegalArgumentException
      A check for properties with names equal to any of the identified discriminator keys
      Parameters:
      discriminatorKeys - the identified discriminator keys throws an IllegalArgumentException if a name of an internally used property is equal to one of the discriminator keys
      Throws:
      IllegalArgumentException