Jaxb.index and nested classes (and OSGi)

When I try to reference nested classes in my jaxb.index file, an exception is thrown during serialization. How can this be avoided?

This is an RCP Eclipse application. The classes that throw the exception are in a different plug-in than the one that creates the JAXB context and initiates serialization. Classes are in one of the exported packages.

The class structure looks like this (names changed):

@XmlRootElement(name="foo") @XmlAccessorType (XmlAccessType.FIELD) public class Foo extends AbstractFoo { ... @XmlRootElement(name="fooMetric") @XmlAccessorType (XmlAccessType.FIELD) public static class FooMetric implements IFooMetric { ... } } 

The jaxb.index file contains the following data:

 Foo Foo.FooMetric 

During serialization, an exception indicates the use of "OuterClass.InnerClass" - what I am doing.

javax. class "or" full.qualified.ClassName "- with the associated exception: [java.lang.ClassNotFoundException: com.mypackage.Foo.FooMetric]

javadocs ( "Format for jaxb.index" ) also assumes that jaxb.index may contain OuterClass.InnerClass form entries.

The class name restrictions that occur in the jaxb.index file are as follows:

  • Cannot end ".class".
  • Class names are resolved relative to the package containing the jaxb.index file. Only classes that occur directly in the package containing the jaxb.index file are allowed.
  • Valid class names are not allowed. The key class name in relation to the current package is allowed to indicate only a nested or inner class.

However, this does not work. What would make it work?

+4
source share
1 answer

The solution I found (trial and error) was to use OuterClass$InnerClass in jaxb.index instead of OuterClass.InnerClass . This allows you to complete serialization.

However, I did not find an authoritative source that recommends this.

[I am posting this solution for a stackoverflow guide , but would like to see and accept a better answer.]

+5
source

Source: https://habr.com/ru/post/1485438/


All Articles