-1

我在将 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 格式。任何想法将不胜感激。

4

1 回答 1

0

根据代码片段 [setData(JAXBElement value)] , setData ,接受 '(JAXBElement') 的实例。但是在这里,您尝试设置一个字符串值 [losRequest.setData(o.toString())] 。在这里,您必须设置一个 'JAXBElement' 的实例。这可能是问题所在。

于 2015-04-21T06:28:37.973 回答