我在将 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));
日志给了我以下输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ApplicationIngestionRequest><BranchCode></BranchCode><SourceCode>0000005511</SourceCode></ApplicationIngestionRequest>
现在,当我尝试将方法设置为
losRequest.setData(o.toString());
它不允许我将其设置为 JAXBElement 格式。任何想法将不胜感激。