使用Dozer的InstantiationException

时间:2015-05-18 21:50:06

标签: dozer instantiationexception

使用Dozer 5.4.0进行映射并从DozerConverter抽象类运行到InstantiationException。这是我的课程,在大多数情况下... BTW - 尝试了List和Map以及HashMap和ArrayList - 没有期待差异而且没有失望!!

public class DozerJAXBElementConverter extends DozerConverter<ArrayList<JAXBElement<String>>, HashMap<String, String>> {

    public DozerJAXBElementConverter(Class<ArrayList<JAXBElement<String>>> prototypeA, Class<HashMap<String, String>> prototypeB) {
        super(prototypeA, prototypeB);
    }  

    @Override
   public ArrayList<JAXBElement<String>> convertFrom(HashMap<String, String> sourceStringMap, ArrayList<JAXBElement<String>> destJaxbList) {

    //Nothign to convert?
    if(sourceStringMap == null || sourceStringMap.isEmpty()) return null;
    //Instantiate list if not already 
    if(destJaxbList == null) destJaxbList = new ArrayList<JAXBElement<String>>();
    //convert
    Iterator<Entry<String, String>> setIterator = sourceStringMap.entrySet().iterator();
    while(setIterator.hasNext()){
        Entry<String,String> e = setIterator.next();
        if(e != null){
            destJaxbList.add(new JAXBElement<String>(new QName(e.getKey(), DozerJAXBElementConverter.NAMESPACE), String.class, e.getValue()));
        }
    }
    return destJaxbList;
}


@Override
public HashMap<String, String> convertTo(ArrayList<JAXBElement<String>> sourceJaxbList, HashMap<String, String> destStringMap) {
    //Nothing to convert?
    if(sourceJaxbList == null || sourceJaxbList.isEmpty()) return null;

    //Instantiate list if not already 
    if(destStringMap == null) destStringMap = new HashMap<String,String>();

    //convert
    Iterator<JAXBElement<String>> i = sourceJaxbList.iterator();
    while(i.hasNext()){
        JAXBElement<String> element = i.next();
        if(element != null){
            destStringMap.put(element.getName().toString(), element.getValue());
        }
    }
    return destStringMap;
}

}}

我实现了适当的方法,所有编译,我得到以下traceat运行时 - 任何帮助表示赞赏:

org.dozer.MappingException: java.lang.InstantiationException: gov.dhs.cbp.ctpat.pip.translate.DozerJAXBElementConverter
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82) ~[dozer-5.4.0.jar:?]
    at org.dozer.util.ReflectionUtils.newInstance(ReflectionUtils.java:360) ~[dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapUsingCustomConverter(MappingProcessor.java:971) ~[dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:345) ~[dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapField(MappingProcessor.java:288) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:248) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:197) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapCustomObject(MappingProcessor.java:495) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:446) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:342) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.mapField(MappingProcessor.java:288) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:248) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:197) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:187) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:124) [dozer-5.4.0.jar:?]
    at org.dozer.MappingProcessor.map(MappingProcessor.java:119) [dozer-5.4.0.jar:?]
    at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120) [dozer-5.4.0.jar:?]

1 个答案:

答案 0 :(得分:1)

我简化为:

public class DozerJAXBElementConverter extends DozerConverter<List, Map> {

    public DozerJAXBElementConverter(Class<List> prototypeA, Class<Map> prototypeB) {
        super(prototypeA, prototypeB);
    }

    public DozerJAXBElementConverter(){
        super(List.class, Map.class);
    }

让它工作 - 不确定原来的impl为什么不起作用......