0

I'm using org.springframework.oxm.jaxb.Jaxb2Marshaller with Spring boot 3 to generated the soap envelope.

At the config, the marshaller is set this way:

@Bean
Jaxb2Marshaller marshalle() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("providers.nos.ws.client"); 
    return marshaller;
}

According to many posts, the way to customize the namespaces alias is by providing a NamespacePrefixMapper like this:

marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapper() {
   @Override
   public String getPreferredPrefix(String arg0, String arg1, boolean arg2) {
            return "ns1";
   }
});

But this only work for old JAXB that is no longer supported since Java 11, if i'm not mistaken.

The setProperty is no longer available. My best guess is adding the following code:

var prefixMapper = new NamespacePrefixMapper(){
        @Override
        public String getPreferredPrefix(String arg0, String arg1, boolean arg2) {
            return "ns1";
        }
};
Map<String, ?> map =   new HashMap<>(){
    {
       put("jakarta.xml.bind.namespacePrefixMapper",prefixMapper);
    }
};
      
marshaller.setJaxbContextProperties(map);

But it fails with:

jakarta.xml.bind.JAXBException: property "jakarta.xml.bind.namespacePrefixMapper" is not supported.

I can't find the right bind constant and i'm not even sure if this is the right path.

How can i customize the namespaces alias?

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

0 Answers0