简体   繁体   中英

Orika - mapping Object (source) to Set(Collection) of Objects (destination)

I have the following classes.

// Source Classes
class SourceEmployer 
{
    private EmployerDetail employerDetail;

    // getters/setters
}
class EmployerDetail
{
   private String name;

   // getters/setters
}

  // Destination Classes
class DestApplication 
{
    private Employment employment;

    // getters/setters
}

class Employment 
{
    private Set<EmployerDetails> employerDetails;

    // getters/setters
}

class EmployerDetails
{
   private String employerName;

   // getters/setters
}

  // Some Mapping configuration

   public DestApplication getOrikaMapping(SourceEmployer source, DestApplication destination)
    {
        MapperFacade mapper;
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        mapperFactory.classMap(source.getClass(), destination.getClass())
                .field("employerDetail.name",
                        "employment.employerDetails{employerName}")
                .byDefault()
                .register();
        mapper = mapperFactory.getMapperFacade();
        DestApplication dto = mapper.map(source, DestApplication.class);
        return dto;
    }

When Execute the above code I have faced the exception below...

------------------------------------------------------------- Unenhance strategy: ma.glasnost.orika.unenhance.BaseUnenhancer@3547efb7 -----end dump of current state------------------------------- at ma.glasnost.orika.impl.ExceptionUtility.newMappingException(ExceptionUtility.java:55) Test au.com.copl.dbaccesslayer.session.WebserviceBeanTest FAILED

It seems it's an Orika bug, I reported it here: https://github.com/orika-mapper/orika/issues/104 .

The bytecode generated for the mapper is incorrect and declares a null variable first and then tries to access it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM