You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "com.test.iso.CustomSupplementary" as an element because it is not known to this context.]`
Setting arbitrary XML in a SupplementaryData Envelope
The error happens because CustomSupplementary is a custom Java class that is not part of the message’s JAXBContext.
JAXB can only marshal types it knows about, meaning the classes returned by mx.getClasses(). Because the custom type is not registered in that context, marshalling fails with:
not known to this context
For xsd:any wildcard content such as SplmtryData/Envlp, you should not use a custom JAXB-annotated class. Instead, set the envelope content as an org.w3c.dom.Element.
The field is annotated with @XmlAnyElement and exposed through:
SupplementaryDataEnvelope1.setAny(Object)
JAXB can marshal a DOM Element directly, without needing to register the class in the JAXB context.
importcom.prowidesoftware.swift.utils.SafeXmlUtils;
importorg.w3c.dom.Document;
importorg.w3c.dom.Element;
importjava.io.StringReader;
importorg.xml.sax.InputSource;
Stringpayload =
"<TEST:TestData xmlns:TEST=\"foocorp:test:smm\">" +
" <TEST:tag>Hello World!</TEST:tag>" +
"</TEST:TestData>";
// Build a namespace-aware, XXE-safe DOM Element from your XMLDocumentdoc = SafeXmlUtils.documentBuilder(true)
.parse(newInputSource(newStringReader(payload)));
Elementelement = doc.getDocumentElement();
SupplementaryDataEnvelope1envlp = newSupplementaryDataEnvelope1();
envlp.setAny(element);
SupplementaryData1splmtry = newSupplementaryData1();
splmtry.setEnvlp(envlp);
// Attach `splmtry` where the schema expects SupplementaryData,// then call mx.message()
Since v10.3.9, this wildcard content is also captured on parse and survives both XML and JSON round-trips.
Previously, JSON emitted:
{
"envelope": {}
}
This was addressed in PWUS-18 / #39 / #43.
See WildcardAnyParsingTest for working examples with:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi, would you give us example how to set our own XML object in any element in Supplementary Data Envelope?
I have give it a try and this shows up on log:
`2022-12-27 07:57:01.069 ERROR 8395 --- [nio-8080-exec-2] c.p.swift.model.mx.MxWriteImpl : Error writing XML:javax.xml.bind.MarshalException
[com.sun.istack.SAXException2: unable to marshal type "com.test.iso.CustomSupplementary" as an element because it is not known to this context.]`
Thank you
All reactions