InstantiationException using Dozer



使用Dozer 5.4.0做映射,我从DozerConverter抽象类中遇到了一个InstantiationException。这是我的班级,大部分是……顺便说一句,我尝试了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;
}

}}

我实现了适当的方法,所有的编译和我得到以下跟踪运行时-任何帮助是感激的:

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:?]

我简化为:

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不工作…

相关内容

  • 没有找到相关文章

最新更新