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:
- Does something like this already exist?
- If not, can something like this be implemented? If so, now?