1

我有一个使用 JAXB 生成标准 XML 的类。我需要对 XML 进行一些更改,以使列表节点不出现,并且列表的内容直接出现在包含节点的列表下方。

package forum11919522;

import java.util.ArrayList;
import java.util.List;

class Person {

    private Property property;

    public Property getProperty() {
        return property;
    }

    public void setProperty(Property property) {
        this.property = property;
    }

    public static class Property {
        private String type;
        private String location;
        private List<Vehicle> vehicle = new ArrayList<Vehicle>();
        /** getter setter omitted **/

    }

    public static class Vehicle {
        private String vin;
        private int year;
        /** getter setter omitted **/
    }

}

当前的xml:

<person>
    <property>
        <type>personal</type>
        <location>abc</location>
        <vehicle>
            <vin>2532</vin>
            <year>2012</year>
        </vehicle>
        <vehicle>
            <vin>125321</vin>
            <year>2010</year>
        </vehicle>
    </property>
</person>

想要的:

<person>
    <property>
        <type>personal</type>
        <location>abc</location>
        <vin>2532</vin>
        <year>2012</year>
        <vin>125321</vin>
        <year>2010</year>
    </property>
</person>

可以用 MOXy 做吗?

4

0 回答 0