Search in sources :

Example 16 with Mapper

use of dev.morphia.mapping.Mapper in project morphia by mongodb.

the class TestBase method fromDocument.

protected <T> T fromDocument(Class<T> type, Document document) {
    Class<T> aClass = type;
    Mapper mapper = getMapper();
    if (document.containsKey(mapper.getOptions().getDiscriminatorKey())) {
        aClass = mapper.getClass(document);
    }
    DocumentReader reader = new DocumentReader(document);
    return getDs().getCodecRegistry().get(aClass).decode(reader, DecoderContext.builder().build());
}
Also used : Mapper(dev.morphia.mapping.Mapper) DocumentReader(dev.morphia.mapping.codec.reader.DocumentReader)

Aggregations

Mapper (dev.morphia.mapping.Mapper)16 Test (org.testng.annotations.Test)13 PathTarget (dev.morphia.internal.PathTarget)8 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)7 ArrayList (java.util.ArrayList)5 Datastore (dev.morphia.Datastore)3 MapperOptions (dev.morphia.mapping.MapperOptions)2 DocumentReader (dev.morphia.mapping.codec.reader.DocumentReader)2 Document (org.bson.Document)2 Nullable (com.mongodb.lang.Nullable)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 Entity (dev.morphia.annotations.Entity)1 MappingException (dev.morphia.mapping.MappingException)1 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 Sofia (dev.morphia.sofia.Sofia)1 CityPopulation (dev.morphia.test.models.CityPopulation)1 State (dev.morphia.test.models.State)1 EmbeddedType (dev.morphia.test.models.generics.EmbeddedType)1 AbstractVersionedBase (dev.morphia.test.models.versioned.AbstractVersionedBase)1 VersionedChildEntity (dev.morphia.test.models.versioned.VersionedChildEntity)1