-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