Удалите xsi: type, xmlns: xs и xmlns: xsi из обобщенных JAXB

При использовании JAXB я хотел бы удалить избыточные пространства имен / типы из моих элементов XML при использовании Generics. Как я могу это сделать или что я делаю не так? Я хотел бы использовать Generics, так что мне нужно написать блок кода только один раз.

Пример кода:

public static void main(String[] args) {
    try {
        TestRoot root = new TestRoot();
        root.name.value = "bobby";
        root.age.value = 102;
        root.color.value = "blue";

        JAXBContext context = JAXBContext.newInstance(root.getClass());
        Marshaller marsh = context.createMarshaller();
        marsh.setProperty(Marshaller.JAXB_ENCODING,"UTF-8");
        marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        marsh.marshal(root,pw);
        System.out.println(sw.toString());
    }
    catch(Throwable t) {
        t.printStackTrace();
    }
}

@XmlRootElement
static class TestRoot {
    @XmlElement public TestGeneric<String> name = new TestGeneric<String>(true);
    @XmlElement public TestGeneric<Integer> age = new TestGeneric<Integer>(true);
    @XmlElement public TestWhatIWouldLike color = new TestWhatIWouldLike(true);
}

@XmlAccessorType(XmlAccessType.NONE)
static class TestGeneric<T> {
    @XmlAttribute public boolean isRequired;
    @XmlElement public T value;

    public TestGeneric() {
    }

    public TestGeneric(boolean isRequired) {
        this.isRequired = isRequired;
    }
}

@XmlAccessorType(XmlAccessType.NONE)
static class TestWhatIWouldLike {
    @XmlAttribute public boolean isRequired;
    @XmlElement public String value;

    public TestWhatIWouldLike() {
    }

    public TestWhatIWouldLike(boolean isRequired) {
        this.isRequired = isRequired;
    }
}

Выход:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testRoot>
    <name isRequired="true">
        <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">bobby</value>
    </name>
    <age isRequired="true">
        <value xsi:type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">102</value>
    </age>
    <color isRequired="true">
        <value>blue</value>
    </color>
</testRoot>

Ответы на вопрос(3)

Ваш ответ на вопрос