2015-01-04 60 views
2

衝突有這個JAXB XML定義,我嘗試通過增加@XmlPath(".")刪除地圖元素包裝,但它的unmarchaling@XmlPath(「」)與@XmlAdapter

@XmlRootElement 
public abstract class ViewElement{ 
    @XmlJavaTypeAdapter(value=EventAdapter.class) 
    public Map<Event, String> getEvents() {  
    } 
    private transient Class entityType; 
    public Class getEntityType() { 
     return entityType; 
    } 
} 

過程中導致異常,EventAdapter是

public class EventAdapter extends XmlAdapter<EventAdapter.AdaptedMap, Map<Event, String>> { 
    public static class AdaptedMap { 
     @XmlVariableNode("key") 
     List<AdaptedEntry> entries = new ArrayList<AdaptedEntry>(); 
    } 
    public static class AdaptedEntry { 
     @XmlTransient 
     public String key; 
     @XmlValue 
     public String value; 
    } 
    .....  
} 

我的輸出是

<element> 
    <events> 
     <onCellEdit>do some thing<onCellEdit> 
    </events> 
    <entityType>com.agitech.erp.model.erp.ErpFolder</entityType> 
<element> 

我儘量去除<events>標籤加入@XmlPath(".")

@XmlPath(".") 
@XmlJavaTypeAdapter(value=EventAdapter.class) 
public Map<Event, String> getEvents() {  
} 

的輸出是不錯

但unmarchaling faileds

Caused by: Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.6.0.v20140809-296a69f): org.eclipse.persistence.exceptions.ConversionException 
Exception Description: The object [], of class [class java.lang.String], from mapping [org.eclipse.persistence.oxm.mappings.XMLDirectMapping[entityType-->view.entityType/text()]] with descriptor [XMLDescriptor(com.agitech.erp.view.BeanView --> [DatabaseTable(view), DatabaseTable(viewFrame), DatabaseTable(viewElement)])], could not be converted to [class java.lang.Class]. 
Internal Exception: java.lang.ClassNotFoundException: 
    at org.eclipse.persistence.exceptions.ConversionException.couldNotBeConvertedToClass(ConversionException.java:95) 
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToClass(ConversionManager.java:446) 

調試運行JAXB帶我到線

org.eclipse.persistence.internal.oxm.XMLDirectMappingNodeValue 

public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) { 
    ... 
    line 205 unmarshalRecord.setAttributeValue(convertedValue, xmlDirectMapping); 
} 

時的EntityType值的unmarchaling,該UnmarshalRecordImpl.currentObj包含EventAdapter父元素

,而不是我修改org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl

public XPathNode getNonAttributeXPathNode(String namespaceURI, String localName, String qName, Attributes attributes) { 
.... 
    if(null == resultNode && null == nonPredicateNode) { 
     // ANY MAPPING 
     resultNode = xPathNode.getAnyNode(); 
// by default it return the EventAdapter, changing it to NULL fix my problem 
    } 
.... 
} 

不是一個安全的解決方案

回答

0

我已經能夠重現問題你正在看,但還沒有找出原因。您可以使用下面的bug跟蹤在這個問題上的進展:

+0

謝謝您的考慮,我添加了一個更好的測試案例,並在評論我目前的不安全的工作解決方案 – 2015-01-10 15:54:11