2012-04-11 60 views
0

我有一個字符串值,我希望使用JAXB將其設置爲一個bean。所以我有一個RuntimeTypeInfoSet的實例,我可以獲得RuntimePropertyInfo,並從該調用getAccessor獲取該屬性的Accessor。問題是Accessor要求該值已經是正確的類型。我如何轉換它?使用JAXB轉換值

+0

'RuntimeTypeInfoSet'是特定於JAXB(JSR-222)參考實現。您是否嘗試使用JAXB實現來填充解組操作之外的對象? – 2012-04-11 10:04:54

回答

1

答案是使用傳感器實例:

switch (property.kind()) { 
    case VALUE: 
    case ATTRIBUTE: 
     transducer = ((RuntimeNonElementRef) property).getTransducer(); 
     break; 
    case ELEMENT: 
     transducer = ((RuntimeElementPropertyInfo) property).getTypes().get(0).getTransducer(); 
     break; 
    case REFERENCE: 
    case MAP: 
    default: 
     throw new UnsupportedOperationException("Don't know how to handle property kind " + property.kind() + " for " + property); 
}