use of dev.morphia.mapping.codec.pojo.MorphiaCodec in project morphia by mongodb.
the class MorphiaCodecProvider method get.
@Nullable
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Codec<T> get(Class<T> type, CodecRegistry registry) {
MorphiaCodec<T> codec = (MorphiaCodec<T>) codecs.get(type);
if (codec == null && (mapper.isMapped(type) || mapper.isMappable(type))) {
EntityModel model = mapper.getEntityModel(type);
codec = new MorphiaCodec<>(datastore, model, propertyCodecProviders, mapper.getDiscriminatorLookup(), registry);
if (model.hasLifecycle(PostPersist.class) || model.hasLifecycle(PrePersist.class) || mapper.hasInterceptors()) {
codec.setEncoder(new LifecycleEncoder(codec));
}
if (model.hasLifecycle(PreLoad.class) || model.hasLifecycle(PostLoad.class) || mapper.hasInterceptors()) {
codec.setDecoder(new LifecycleDecoder(codec));
}
codecs.put(type, codec);
}
return codec;
}
Aggregations