Search in sources :

Example 41 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project tutorials by eugenp.

the class OrikaUnitTest method givenSrcWithNullAndGlobalConfigForNoNull_whenFailsToMap_ThenCorrect.

@Test
public void givenSrcWithNullAndGlobalConfigForNoNull_whenFailsToMap_ThenCorrect() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().mapNulls(false).build();
    mapperFactory.classMap(Source.class, Dest.class);
    MapperFacade mapper = mapperFactory.getMapperFacade();
    Source src = new Source(null, 10);
    Dest dest = new Dest("Clinton", 55);
    mapper.map(src, dest);
    assertEquals(dest.getAge(), src.getAge());
    assertEquals(dest.getName(), "Clinton");
}
Also used : BoundMapperFacade(ma.glasnost.orika.BoundMapperFacade) MapperFacade(ma.glasnost.orika.MapperFacade) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) Test(org.junit.Test)

Example 42 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project useful-java-links by Vedenin.

the class OrikaHelloWorld method main.

public static void main(String[] args) {
    // init mapper
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    mapperFactory.classMap(Source.class, Destination.class).field("message", "text").register();
    MapperFacade mapper = mapperFactory.getMapperFacade();
    // convert
    Source source = new Source("Hello World!");
    Destination destObject = mapper.map(source, Destination.class);
    // print Hello World!
    destObject.print();
}
Also used : MapperFacade(ma.glasnost.orika.MapperFacade) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory)

Aggregations

MapperFactory (ma.glasnost.orika.MapperFactory)42 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)42 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)9 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)9 MappingContext (ma.glasnost.orika.MappingContext)4 NotificationWorkEntity (org.orcid.persistence.jpa.entities.NotificationWorkEntity)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 MapperFacade (ma.glasnost.orika.MapperFacade)2 ExternalIdentifierTypeConverter (org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter)2 JSONWorkExternalIdentifiersConverterV2 (org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV2)2 JSONWorkExternalIdentifiersConverterV3 (org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV3)2 OtherName (org.orcid.jaxb.model.record_v2.OtherName)2 RecordCorrection (org.orcid.model.record_correction.RecordCorrection)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)2