没有为属性 [CO] 提供转化值
No conversion value provided for the attribute [CO]
我有一个 xsd,它包含一个实体地址,它有一个 属性 country_code,它有枚举类型。我无法从根实体中编组 xml,因为它会抛出如下异常
javax.xml.bind.MarshalException
- with linked exception: [Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: An error occurred marshalling the object Internal
Exception: Exception [EclipseLink-115] (Eclipse Persistence Services -
2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception
Description: No conversion value provided for the attribute [CO].
Mapping:
org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()]
Descriptor: XMLDescriptor(generated.TAddress --> [])] at
org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:403)
at
com.crrinfra.dynamicOutputgen.utils.HelloWorld.generateTransaction(HelloWorld.java:52)
at
com.crrinfra.dynamicOutputgen.utils.XMLUtilities.generateJaxBContext(XMLUtilities.java:259)
at
com.crrinfra.dynamicOutputgen.utils.DynamicXSDLoader.populateCache(DynamicXSDLoader.java:48)
at
com..crrinfra.dynamicOutputgen.DynamicOutputXSDParser.main(DynamicOutputXSDParser.java:16)
Caused by: Exception [EclipseLink-25003] (Eclipse Persistence Services
- 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException Exception
Description: An error occurred marshalling the object Internal
Exception: Exception [EclipseLink-115] (Eclipse Persistence Services -
2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception
Description: No conversion value provided for the attribute [CO].
Mapping:
org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()]
Descriptor: XMLDescriptor(generated.TAddress --> []) at
org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:97)
at
org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:911)
at
org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:848)
at
org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:401)
... 4 more
publicclass你好世界{
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 这个问题
我找到了问题的答案,因此想关闭此线程。我很乐意收到有关此方法的反馈
public class EnumAttributeHandler implements IAttributeHandler {
DynamicTypeImpl typeAttr;
public EnumAttributeHandler(DynamicTypeImpl typeAttr) {
// TODO Auto-generated constructor stub
this.typeAttr=typeAttr;
}
@Override
public DynamicEntity attributeSetter(CRROutputAttributePojo attrPojo, DynamicEntity currentEntitytag, HashMap<String, Object> params,String setterValue) throws CRROutputGenException {
// TODO Auto-generated method stub
XMLDirectMapping enumMappings = (XMLDirectMapping) (typeAttr)
.getMapping(attrPojo.getActualAttrName());
EnumTypeConverter converter=null;
if(enumMappings.getConverter() instanceof EnumTypeConverter)
converter = (EnumTypeConverter) enumMappings.getConverter();
else
throw new CRROutputGenException("Invalid type of converter");
try {
if (setterValue != null) {
Object enumField = ((DynamicJAXBContext) params.get("jaxbContext")).getEnumConstant(converter.getEnumClassName().toString(), setterValue);
currentEntitytag.set(attrPojo.getActualAttrName(), enumField);
}
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new CRROutputGenException(e.getMessage());
}
return currentEntitytag;
}
}
我有一个 xsd,它包含一个实体地址,它有一个 属性 country_code,它有枚举类型。我无法从根实体中编组 xml,因为它会抛出如下异常
javax.xml.bind.MarshalException - with linked exception: [Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: An error occurred marshalling the object Internal Exception: Exception [EclipseLink-115] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception Description: No conversion value provided for the attribute [CO]. Mapping: org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()] Descriptor: XMLDescriptor(generated.TAddress --> [])] at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:403) at com.crrinfra.dynamicOutputgen.utils.HelloWorld.generateTransaction(HelloWorld.java:52) at com.crrinfra.dynamicOutputgen.utils.XMLUtilities.generateJaxBContext(XMLUtilities.java:259) at com.crrinfra.dynamicOutputgen.utils.DynamicXSDLoader.populateCache(DynamicXSDLoader.java:48) at com..crrinfra.dynamicOutputgen.DynamicOutputXSDParser.main(DynamicOutputXSDParser.java:16) Caused by: Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: An error occurred marshalling the object Internal Exception: Exception [EclipseLink-115] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception Description: No conversion value provided for the attribute [CO]. Mapping: org.eclipse.persistence.oxm.mappings.XMLDirectMapping[countryCode-->country_code/text()] Descriptor: XMLDescriptor(generated.TAddress --> []) at org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:97) at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:911) at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:848) at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:401) ... 4 more
publicclass你好世界{
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 这个问题
我找到了问题的答案,因此想关闭此线程。我很乐意收到有关此方法的反馈
public class EnumAttributeHandler implements IAttributeHandler {
DynamicTypeImpl typeAttr;
public EnumAttributeHandler(DynamicTypeImpl typeAttr) {
// TODO Auto-generated constructor stub
this.typeAttr=typeAttr;
}
@Override
public DynamicEntity attributeSetter(CRROutputAttributePojo attrPojo, DynamicEntity currentEntitytag, HashMap<String, Object> params,String setterValue) throws CRROutputGenException {
// TODO Auto-generated method stub
XMLDirectMapping enumMappings = (XMLDirectMapping) (typeAttr)
.getMapping(attrPojo.getActualAttrName());
EnumTypeConverter converter=null;
if(enumMappings.getConverter() instanceof EnumTypeConverter)
converter = (EnumTypeConverter) enumMappings.getConverter();
else
throw new CRROutputGenException("Invalid type of converter");
try {
if (setterValue != null) {
Object enumField = ((DynamicJAXBContext) params.get("jaxbContext")).getEnumConstant(converter.getEnumClassName().toString(), setterValue);
currentEntitytag.set(attrPojo.getActualAttrName(), enumField);
}
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new CRROutputGenException(e.getMessage());
}
return currentEntitytag;
}
}