webservice与spring集成,自己写的输出xml的方法
public static String marshal(Object o) {
try {
JAXBContext jAXBContext = JAXBContext.newInstance(o.getClass());
// JAXBContext jAXBContext = JAXBContext.newInstance(Category.class);
final Marshaller marshaller = jAXBContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// Create a stringWriter to hold the XML
final StringWriter stringWriter = new StringWriter();
// Marshal the javaObject and write the XML to the stringWriter
marshaller.marshal(o, stringWriter);
String chartXml = stringWriter.toString();
return chartXml;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
但是对像中有@XmlAttribute 属性,反而会报错
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
有两个名为 "time" 的属性
this problem is related to the following location:
at public java.lang.String com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData.getTime()
at com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData
this problem is related to the following location:
at private java.lang.String com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData.time
at com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData
类的两个属性具有相同名称 "time"
this problem is related to the following location:
at public java.lang.String com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData.getTime()
at com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData
this problem is related to the following location:
at private java.lang.String com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData.time
at com.ldalc.modules.open.pojo.DataTransmissionEnergyResponseData
去掉反而成功输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<common>
<building_id>1111</building_id>
</common>
<time>22222222</time>
</root>