How to clarify type info for generic field in abstract class for JAXB?

У меня есть abstract class AbstractSection<T>, в котором представлено поле protected T content, от этого класса наследуется множество других, в том числе ListSection extends AbstractSection<List<String>>. То есть, в нем тип поля List<String>, но явно оно в классе не появляется.

При попытке маршализировать пакет с помощью JAXB - получаю class java.util.Arrays$ArrayList nor any of its super class is known to this context.. Ответы на вопросы аля "JAXB and generics" - дают различные варианты, но все подразумевают, что мы можем явно указать класс (@seeAlso или прочие), который лежит в поле. Но я этого сделать не могу - во-первых этого поля нет в явном виде в наследниках, во-вторых - List.class тут не поможет, а List<String>.class конструкция, ясно дело, бесполезная. Кратенькие примеры кода привожу ниже. В соответсвующем рутовом классе указана @XMLRootElement, тут ошибки нет.

Как побороть этого зверя, подскажите пожалуйста?

@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractSection<T> implements Serializable {

 protected T content;

 public AbstractSection() {
 }

 public AbstractSection(T content) {
     Objects.requireNonNull(content, "content must be not null");
     this.content = content;
 }

 public void setContent(T content) {
     this.content = content;
 }

 public T getContent() {
     return content;
 }

}
@XmlAccessorType(XmlAccessType.FIELD)
public class ListSection extends AbstractSection<List<String>> {
    public ListSection() {
    }

    public ListSection(List<String> info) {
        super(info);
    }

}
JAXBContext context = JAXBContext.newInstance(Resume.class, AbstractSection.class, ListSection.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(r, os);

Ответы (0 шт):