Discussed in #314
Originally posted by patricklucas November 12, 2025
I am aware I can use the @XmlNamespaceDeclSpecs annotation to include namespace declarations on an element, but is there a way to tack those on at serialization time rather than using an annotation?
My use-case is that part of the element structure is described as xs:any, and I'm successfully using CompactFragment to handle this content, and I would like consumers of the library containing the serializable classes to be able to add namespace declarations to the root element when serializing so that the declaration doesn't have to be included on every single CompactFragment instance that uses that namespace.
In my case, a document can have thousands of such inner elements, and it would be nice to have the namespace declared just once. The library itself is not aware of what namespaces a consumer might want to use, so it cannot preemptively include them using @XmlNamespaceDeclSpecs.
I traced the code just a bit, and found that ultimately the decls are exposed in the descriptor via a call to config.policy.elementNamespaceDecls, so perhaps there is a way (or could be a way) to provide additional namespace declarations on the serializer config?
Discussed in #314
Originally posted by patricklucas November 12, 2025
I am aware I can use the
@XmlNamespaceDeclSpecsannotation to include namespace declarations on an element, but is there a way to tack those on at serialization time rather than using an annotation?My use-case is that part of the element structure is described as
xs:any, and I'm successfully usingCompactFragmentto handle this content, and I would like consumers of the library containing the serializable classes to be able to add namespace declarations to the root element when serializing so that the declaration doesn't have to be included on every singleCompactFragmentinstance that uses that namespace.In my case, a document can have thousands of such inner elements, and it would be nice to have the namespace declared just once. The library itself is not aware of what namespaces a consumer might want to use, so it cannot preemptively include them using
@XmlNamespaceDeclSpecs.I traced the code just a bit, and found that ultimately the decls are exposed in the descriptor via a call to
config.policy.elementNamespaceDecls, so perhaps there is a way (or could be a way) to provide additional namespace declarations on the serializer config?