-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom namespace marshalling using JAXB RI results in property "org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper" is not supported #1795
Comments
Regards, |
@antoniosanct Thanks a lot for the response. For your convience I have added the sample code repo here: https://github.com/Aravinda93/test/tree/main I was trying couple of things thats the reason I added the As you mentioned I have removed the
Following is my main class updated: import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Marshaller;
import java.util.HashMap;
import java.util.Map;
public class MainXML {
public static void main(String[] args) throws Exception {
final Map<String, String> myNamespaces = new HashMap<>();
myNamespaces.put("test", "https://test.com");
myNamespaces.put("test2", "https://test2.com");
final JAXBContext jaxbContext = JAXBContext.newInstance("io.test.convert", Thread.currentThread().getContextClassLoader(),
new HashMap<>() {
{
put(
"org.glassfish.jaxb.namespacePrefixMapper",
new CustomNamespacePrefixMapper());
}
});
//final JAXBContext jaxbContext = JAXBContext.newInstance("io.test.convert", Thread.currentThread().getContextClassLoader());
final Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty("org.glassfish.jaxb.namespacePrefixMapper", new CustomNamespacePrefixMapper());
final Child1 child1 = new Child1();
child1.setName("Batman");
child1.setAge("30");
child1.setType("Superhero");
child1.setOriginalName("Bruce Wayne");
marshaller.marshal(child1, System.out);
}
} |
@Aravinda93 Regards, |
For convience I have added the sample code repo here: https://github.com/Aravinda93/test/tree/main
I am using JAXB RI to marshall the Java objects into XML but during the marshalling I need to provide some of the custom namespaces to my
Marshaller
andJAXBContext
. I referred the documentation and answer here to do the same but its resulting in the error:Following is the completed code I have:
Child1.class
:Parent.class
:CustomNamespacePrefixMapper.class
:MainXML.class
:Following is my
sampleXML.xml
:ObjectFactory.class
:When I run I get the error:
How to provide the custom namespaces to the
JAXBContext/Marshaller
so it can be used during the marshalling of the Java objects to XML?Following are my dependencies:
The text was updated successfully, but these errors were encountered: