Class MorphiaCodec<T>

  • Type Parameters:
    T - the entity type
    All Implemented Interfaces:
    org.bson.codecs.Codec<T>, org.bson.codecs.CollectibleCodec<T>, org.bson.codecs.Decoder<T>, org.bson.codecs.Encoder<T>

    public class MorphiaCodec<T>
    extends Object
    implements org.bson.codecs.CollectibleCodec<T>
    the codec used by Morphia
    Since:
    2.0
    Developer note.
    This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • Constructor Detail

      • MorphiaCodec

        public MorphiaCodec​(Datastore datastore,
                            EntityModel model,
                            List<org.bson.codecs.pojo.PropertyCodecProvider> propertyCodecProviders,
                            DiscriminatorLookup discriminatorLookup,
                            org.bson.codecs.configuration.CodecRegistry registry)
        Creates a new codec
        Parameters:
        datastore - the datastore
        model - the model backing this codec
        propertyCodecProviders - the codec provider for properties
        registry - the codec registry for lookups
        discriminatorLookup - the discriminator to type lookup
    • Method Detail

      • decode

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

        public boolean documentHasId​(Object entity)
        Specified by:
        documentHasId in interface org.bson.codecs.CollectibleCodec<T>
      • getEntityModel

        public EntityModel getEntityModel()
        Returns:
        the entity model backing this codec
      • getEncoder

        public dev.morphia.mapping.codec.pojo.EntityEncoder getEncoder()
        Returns:
        the encoder
      • setEncoder

        public MorphiaCodec<T> setEncoder​(dev.morphia.mapping.codec.pojo.EntityEncoder encoder)
        Sets the encoder
        Parameters:
        encoder - the encoder
        Returns:
        this
      • getDecoder

        protected EntityDecoder getDecoder()
        Returns:
        the decoder
      • setDecoder

        public void setDecoder​(EntityDecoder decoder)
        Sets the decoder
        Parameters:
        decoder - the decoder
      • encode

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

        public Class getEncoderClass()
        Specified by:
        getEncoderClass in interface org.bson.codecs.Encoder<T>
      • generateIdIfAbsentFromDocument

        public Object generateIdIfAbsentFromDocument​(Object entity)
        Specified by:
        generateIdIfAbsentFromDocument in interface org.bson.codecs.CollectibleCodec<T>
      • getDocumentId

        public org.bson.BsonValue getDocumentId​(Object document)
        Specified by:
        getDocumentId in interface org.bson.codecs.CollectibleCodec<T>
      • getMapper

        public Mapper getMapper()
        Returns:
        the mapper being used