Package dev.morphia.mapping.codec.pojo
Class MorphiaCodec<T>
- java.lang.Object
-
- dev.morphia.mapping.codec.pojo.MorphiaCodec<T>
-
- Type Parameters:
T
- the entity type
- All Implemented Interfaces:
Codec<T>
,CollectibleCodec<T>
,Decoder<T>
,Encoder<T>
@MorphiaInternal public class MorphiaCodec<T> extends Object implements 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 Summary
Constructors Constructor Description MorphiaCodec(Datastore datastore, EntityModel model, List<PropertyCodecProvider> propertyCodecProviders, DiscriminatorLookup discriminatorLookup, CodecRegistry registry)
Creates a new codec
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
decode(BsonReader reader, DecoderContext decoderContext)
boolean
documentHasId(Object entity)
void
encode(BsonWriter writer, T value, EncoderContext encoderContext)
Object
generateIdIfAbsentFromDocument(Object entity)
Datastore
getDatastore()
protected EntityDecoder<T>
getDecoder()
DiscriminatorLookup
getDiscriminatorLookup()
BsonValue
getDocumentId(Object document)
EntityEncoder<T>
getEncoder()
Class<T>
getEncoderClass()
EntityModel
getEntityModel()
Mapper
getMapper()
CodecRegistry
getRegistry()
MorphiaCodec<T>
setDecoder(EntityDecoder<T> decoder)
Sets the decoderMorphiaCodec<T>
setEncoder(EntityEncoder<T> encoder)
Sets the encoder
-
-
-
Constructor Detail
-
MorphiaCodec
public MorphiaCodec(Datastore datastore, EntityModel model, List<PropertyCodecProvider> propertyCodecProviders, DiscriminatorLookup discriminatorLookup, CodecRegistry registry)
Creates a new codec- Parameters:
datastore
-model
- the model backing this codecpropertyCodecProviders
- the codec provider for propertiesdiscriminatorLookup
- the discriminator to type lookupregistry
- the codec registry for lookups
-
-
Method Detail
-
decode
public T decode(BsonReader reader, DecoderContext decoderContext)
-
encode
public void encode(BsonWriter writer, T value, EncoderContext encoderContext)
-
getEncoderClass
public Class<T> getEncoderClass()
- Specified by:
getEncoderClass
in interfaceEncoder<T>
-
generateIdIfAbsentFromDocument
public Object generateIdIfAbsentFromDocument(Object entity)
- Specified by:
generateIdIfAbsentFromDocument
in interfaceCollectibleCodec<T>
-
documentHasId
public boolean documentHasId(Object entity)
- Specified by:
documentHasId
in interfaceCollectibleCodec<T>
-
getDocumentId
public BsonValue getDocumentId(Object document)
- Specified by:
getDocumentId
in interfaceCollectibleCodec<T>
-
getDatastore
public Datastore getDatastore()
- Returns:
- the datastore
- Since:
- 2.3
-
getDiscriminatorLookup
public DiscriminatorLookup getDiscriminatorLookup()
- Returns:
- the DiscriminatorLookup
-
getEncoder
public EntityEncoder<T> getEncoder()
- Returns:
- the encoder
- Since:
- 2.3
-
setEncoder
public MorphiaCodec<T> setEncoder(EntityEncoder<T> encoder)
Sets the encoder- Parameters:
encoder
- the encoder- Returns:
- this
-
getEntityModel
public EntityModel getEntityModel()
- Returns:
- the entity model backing this codec
-
getMapper
public Mapper getMapper()
- Returns:
- the mapper being used
-
getRegistry
public CodecRegistry getRegistry()
- Returns:
- the codec registry
-
getDecoder
protected EntityDecoder<T> getDecoder()
- Returns:
- the decoder
-
setDecoder
public MorphiaCodec<T> setDecoder(EntityDecoder<T> decoder)
Sets the decoder- Parameters:
decoder
- the decoder- Returns:
-
-