0

The docs for the annotation type @XmlElements has this example:

public class Foo {
    @XmlElements(
        @XmlElement(name="A", type=Integer.class),
        @XmlElement(name="B", type=Float.class)
     }
     public List items;
}

This is great when you only have a few known types that need to be in the list. I am looking for a way to make it more dynamic so that when new elements are added to the system class Foo does not need to be modified.

The first thing that comes to mind is using some custom annotations. Lets call it @XmlElementType and it has a attribute of type which would be applied to the elements (Integer, Float, etc). Of course this cannot be done to predefined types, it would only apply to new types.

Then an variant of the annotation @XmlElements would be applied to the List items in class Foo. It would have a attribute to indicate the type of @XmlElementType which it can contain, maybe a package to scan for the POJO's.

So I have two questions:

  1. Does something like this already exist?
  2. If not, can something like this be implemented? If so, now?
Sam Carleton
  • 1,339
  • 7
  • 23
  • 45

1 Answers1

0

I think you can use type of Object.class and then use XmlAnyElement. If you can give a concrete example, what you want to achieve, then it will be possible for me to edit the answer and give concrete example.

Optional
  • 4,387
  • 4
  • 27
  • 45