简体   繁体   English

Orika-将对象(源)映射到对象(目的地)的集合(集合)

[英]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 -------------------------------------------------- -----------取消策略:ma.glasnost.orika.unenhance.BaseUnenhancer@3547efb7 -----当前状态的最终转储--------------- ----------------在ma.glasnost.orika.impl.ExceptionUtility.newMappingException(ExceptionUtility.java:55)测试au.com.copl.dbaccesslayer.session.WebserviceBeanTest失败

It seems it's an Orika bug, I reported it here: https://github.com/orika-mapper/orika/issues/104 . 看来这是一个Orika错误,我在这里报告了它: 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. 为映射器生成的字节码不正确,并且先声明一个null变量,然后尝试访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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