1

I'm migrating from WAS to Liberty where in we are having JAXB as application dependency. I have extended the NamespaceMapper of the jaxb-impl and when I'm trying to set it to Marshaller Property I'm getting the error that the nampespace mapper should be instance of com.sun.xml.bind.marshaller.NamespacePrefixMapper and not of my custom namespace mapper.

public class MyNamespaceMapper extends com.sun.xml.bind.marshaller.NamespacePrefixMapper{
// custom logic.
}
JAXBContext context =JAXBContext.newInstance("class");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new MyNamespaceMapper());

I have tried changing the delegation to parent last for the jaxb library but then I run into classloader issues. I tried using the ContextClassLoader but I keep running into the same issue. I tried creating the liberty user feature as well but I was unable run it correctly. Here is the maifest files of the feature I tried to create.

Feature-marshaller.MF


Subsystem-ManifestVersion: 1.0
Subsystem-SymbolicName: m-1.0.0; visibility:=public
Subsystem-Version: 1.0.0.qualifier
Subsystem-Type: osgi.subsystem.feature
Subsystem-Content: marshaller; version="[1,1.0.100)"
IBM-Feature-Version: 2
IBM-API-Package: com.sun.xml.bind.marshaller; type="api"
IBM-ShortName: m-1.0.0

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: marshaller
Bundle-SymbolicName: marshaller
Bundle-Version: 1.0.0
Import-Package: org.osgi.framework
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.sun.xml.bind.marshaller
Bundle-ClassPath: jaxb-impl-1.0.jar

I tried to create this OSGI bundle from the option create plugin from existing jar and I pointed to the jaxb jar. and then I created these Manifeyour textst files.

Can someone please help me fix this issue?

Igupta
  • 31
  • 2

1 Answers1

1

unfortunately, I do not think it's possible to extend the NamespacePrefixMapper class while using the jaxb-2.2 feature on Liberty. I've tested this myself with a custom user feature, and hit a NoClassDefFoundError. The reason this doesn't work with a user feature, is that the jaxb-2.2 OSGi feature was written very intentionally to not expose any of the internal implementation packages, com.sun.xml.bind.*, as IBM-API-Package in it's feature manifest file.

If you have a hard dependency on the NamespacePrefixMapper class, you might think about packaging your own JAXB specification and implementation and not enabling the jaxb-2.2 feature on Liberty. You might also look at alternatives to using the NamespacePrefixMapper. You may or may not find this link useful for that Define Spring JAXB namespaces without using NamespacePrefixMapper.