将String对象转换为JAXBElement字符串对象时我遇到了一些问题,我需要设置此对象
这是我需要设置值
的目标方法public void setData(JAXBElement<String> value) {
this.data = ((JAXBElement<String> ) value);
}
对于这个,我编写了类似这样的代码
ObjectFactory factory = new ObjectFactory();
JAXBElement<ApplicationIngestionRequest> jaxbElement = new JAXBElement(
new QName(ApplicationIngestionRequest.class.getSimpleName()), ApplicationIngestionRequest.class, request);
StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(ApplicationIngestionRequest.class);
context.createMarshaller().marshal(jaxbElement, writer);
LOG.info("JAXBElement object :\n"+ writer.toString());
Unmarshaller u = context.createUnmarshaller();
JAXBElement<ApplicationIngestionRequest> o = (JAXBElement<ApplicationIngestionRequest>) u.unmarshal(new StringReader(writer));
Log给出了以下输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ApplicationIngestionRequest><BranchCode></BranchCode><SourceCode>0000005511</SourceCode></ApplicationIngestionRequest>
现在当我尝试将方法设置为
时losRequest.setData(o.toString());
它不允许我将其设置为JAXBElement格式。任何想法将不胜感激。
答案 0 :(得分:0)
根据代码片段[setData(JAXBElement value)],setData,接受&#39;(JAXBElement&#39;)的实例。但是在这里,您正在尝试设置字符串值[losRequest.setData(o.toString())]。在这里你必须设置一个&#39; JAXBElement&#39;的实例。这可能是个问题。