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,
                            MappedClass mappedClass,
                            List<org.bson.codecs.pojo.PropertyCodecProvider> propertyCodecProviders,
                            DiscriminatorLookup discriminatorLookup,
                            org.bson.codecs.configuration.CodecRegistry registry)
        Creates a new codec
        Parameters:
        datastore - the datastore
        mappedClass - the MappedClass 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>
      • getEntityModel

        public EntityModel<T> getEntityModel()
        Returns:
        the entity model backing this codec
      • encode

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

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

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

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

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

        public MappedClass getMappedClass()
        Returns:
        the MappedClass for this codec
      • getMapper

        public Mapper getMapper()
        Returns:
        the mapper being used