我在将String对象转换为JAXBElement字符串对象时遇到了一些问题,我需要设置此对象
这是我需要设置值的目标方法
public void setData(JAXBElement value) {
this.data = ((JAXBElement ) value);
}对于这个,我写了类似这样的代码
ObjectFactory factory = new ObjectFactory();
JAXBElement 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 o = (JAXBElement) u.unmarshal(new StringReader(writer));日志给我下面的输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>0000005511现在,当我尝试将方法设置为
losRequest.setData(o.toString());它不允许将其设置为JAXBElement格式。任何想法将不胜感激。