【发布时间】:2018-09-16 12:00:13
【问题描述】:
我有一个 xsd,它包含一个实体 Taddress,该实体 Taddress 具有一个枚举类型的属性 country_code。我无法将 xml 编组出根实体,因为它会引发如下异常
javax.xml.bind.MarshalException - 带有链接异常:[异常 [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException 异常 说明:编组内部对象时发生错误 异常:异常 [EclipseLink-115](Eclipse 持久性服务 - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException 异常 说明:没有为属性 [CO] 提供转换值。 映射: org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()] 描述符:XMLDescriptor(generated.TAddress --> [])] at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:403) 在 com.crrinfra.dynamicOutputgen.utils.HelloWorld.generateTransaction(HelloWorld.java:52) 在 com.crrinfra.dynamicOutputgen.utils.XMLUtilities.generateJaxBContext(XMLUtilities.java:259) 在 com.crrinfra.dynamicOutputgen.utils.DynamicXSDLoader.populateCache(DynamicXSDLoader.java:48) 在 com..crrinfra.dynamicOutputgen.DynamicOutputXSDParser.main(DynamicOutputXSDParser.java:16) 原因:异常 [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.XMLMarshalException 异常 说明:编组内部对象时发生错误 异常:异常 [EclipseLink-115](Eclipse 持久性服务 - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException 异常 说明:没有为属性 [CO] 提供转换值。 映射: org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()] 描述符:XMLDescriptor(generated.TAddress --> []) at org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:97) 在 org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:911) 在 org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:848) 在 org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:401) ... 4 更多
公共类 HelloWorld {
public static void generateTransaction(DynamicJAXBContext jaxbContext) throws JAXBException, NoSuchFieldException, SecurityException{
DynamicEntity entity = jaxbContext.newDynamicEntity("generated.Report");
DynamicType type = jaxbContext.getDynamicType("generated.Report");
DynamicEntity childEntity3 = jaxbContext.newDynamicEntity("generated.TAddress");
DynamicType type1 = jaxbContext.getDynamicType("generated.TAddress");
childEntity3.set("addressType", "M");
childEntity3.set("address", "XXXX");
childEntity3.set("town", "XXX");
childEntity3.set("city", "XXXXX");
childEntity3.set("zip", "751006");
childEntity3.set("countryCode", "CO");
childEntity3.set("state", "OD");
childEntity3.set("comments", "Permanent Address");
entity.set("location", childEntity3);
XMLDirectMapping enumMappings = (XMLDirectMapping) ((DynamicTypeImpl) type1).getMapping("countryCode");
System.out.println(enumMappings.isDirectToFieldMapping());
JAXBMarshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(entity, System.out);
}
}
请告知如何设置属性。我已经上传了这个问题的xsd
【问题讨论】:
标签: jaxb eclipselink moxy