【发布时间】:2013-12-30 10:52:42
【问题描述】:
JAXB 用于将 java 对象编组到文件中。
@XmlRootElement
public class CompleteCollectionInfo {
@XmlElement(required = true)
@XmlID
@XmlSchemaType(name = "ID")
protected String uid;
}
@XmlRootElement
public class AssociationInfo {
@XmlElement(required = true)
@XmlIDREF
@XmlSchemaType(name = "IDREF")
@XmlJavaTypeAdapter(type= CompleteCollectionInfo.class , value =AssociationCompleteCollectionInfoAdapter.class)
protected CompleteCollectionInfo associatedcollection;
}
适配器将确保所有 CompleteCollectionInfo 引用(如果之前未编组)在关联信息中正确设置
public class AssociationCompleteCollectionInfoAdapter extends XmlAdapter<String, CompleteCollectionInfo>{
@Override
public CompleteCollectionInfo unmarshal(String v) throws Exception {
CompleteCollectionInfo completeCollectionInfo = UnBlobUtil.completeCollectionCache.get(v);
if (completeCollectionInfo == null )
completeCollectionInfo = new CompleteCollectionInfo();
completeCollectionInfo.setUid(v);
return completeCollectionInfo;
}
@Override
public String marshal(CompleteCollectionInfo v) throws Exception {
return v.getUid();
}
}
编组时遇到的异常: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:1 个 IllegalAnnotationExceptions 计数 XmlIDREF 属性引用了没有 XmlID 属性的类型“java.lang.String”。
【问题讨论】:
-
你能发布 Group.xml 吗?