自定义转换器上的Dozer,InstantiationException

Gar*_*lon 3 mapping converter dozer instantiationexception

我写了自己的客户转换器:

public class MyFancyCustomConverter extends DozerConverter<Integer, AnObject>
{
    public MyFancyCustomConverter(Class<Integer> prototypeA, Class<AnObject> prototypeB)
    {
        super(prototypeA, prototypeB);
    }

    @Override
    public AnObject convertTo(Integer source, AnObject destination)
    {
        // TODO: do something
        return null;
    }

    @Override
    public Integer convertFrom(AnObject source, Integer destination)
    {
        // TODO: do something
        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的mapping.xml:

<mapping>
    <class-a>java.lang.Integer</class-a>
    <class-b>xyz.AnObject</class-b>
    <field custom-converter="xyz.MyFancyCustomConverter" custom-converter-param="hello">
      <a>this</a>
      <b key="my.key">this</b>
    </field>
</mapping>
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个例外:

org.dozer.MappingException:java.lang.InstantiationException:xyz.MyFancyCustomConverter

知道我做错了什么吗?我想这是因为MyFancyCustomConverter没有默认转换器.但我不能添加一个,因为DozerConverter没有...

art*_*tol 13

public MyFancyCustomConverter(Class<Integer> prototypeA, Class<AnObject> prototypeB)
{
    super(prototypeA, prototypeB);
}
Run Code Online (Sandbox Code Playgroud)

应该

public MyFancyCustomConverter()
{
    super(Integer.class, AnObject.class);
}
Run Code Online (Sandbox Code Playgroud)

超类需要知道这两个类的运行时类型,并且由于类型擦除,需要传入一个类型标记.