Mapping – dozer, instantiationexception on custom converter

I wrote my own customer converter:

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;
    }
}

My 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>

But I got this exception:

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

You know what I did wrong? I think this is because myfancycustomconverter has no default converter But I can't add one because dozerconverter doesn't

Solution

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

should

public MyFancyCustomConverter()
{
    super(Integer.class,AnObject.class);
}

The superclass needs to know the runtime types of these two classes, and a type tag needs to be passed in due to type erasure

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>