Orika mapper NPE在2张地图之间

时间:2018-05-16 00:51:56

标签: java javabeans orika

我有两个具有相同“链接”属性的对象,当使用Orika从A - >映射时B,我得到

  ma.glasnost.orika.MappingException:ma.glasnost.orika.MappingException: 
While attempting the following mapping:
    sourceType = A
    sourceProperty = links(Links)
    destinationType = B
    destinationProperty = links(Links)
    Error occurred: java.lang.NullPointerException
Caused by: ma.glasnost.orika.MappingException: java.lang.NullPointerException
    at ma.glasnost.orika.impl.generator.MapperGenerator.addMapMethod(MapperGenerator.java:170)
    at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:70)
    ... 49 common frames omitted
Caused by: java.lang.NullPointerException: null
    at ma.glasnost.orika.impl.generator.VariableRef.isPrimitive(VariableRef.java:167)
    at ma.glasnost.orika.impl.generator.VariableRef.<init>(VariableRef.java:95)
    at ma.glasnost.orika.impl.generator.specification.MapToMap.generateMappingCode(MapToMap.java:71)
    at ma.glasnost.orika.impl.generator.SourceCodeContext.mapFields(SourceCodeContext.java:778)
    at ma.glasnost.orika.impl.generator.MapperGenerator.generateFieldMapCode(MapperGenerator.java:247)
    at ma.glasnost.orika.impl.generator.MapperGenerator.addMapMethod(MapperGenerator.java:167)
    ... 50 common frames omitted

对象的定义如下:

class A {
  private Links links
  // getter/setter + other fields
}

class B { 
  private Links links
  // getter/setter + other fields
}

class Links extends HashMap<String, List<Link>> {
}

class Link {
  private String text;
}

我正在使用默认映射器:

mapper.classMap(A.class, B.class)
      .byDefault()
      .register();

有任何建议吗?

1 个答案:

答案 0 :(得分:1)

你看到了这个: https://code.google.com/archive/p/orika/issues/170

它说这个问题在这里得到了解决,但对我来说看起来并不一样:https://github.com/orika-mapper/orika/issues/67

或者也许这就是你所看到的: https://github.com/orika-mapper/orika/issues/232

您的问题与code.google.com

上发布的问题相同