1

i had problems with jaxb. I need to resolv this :

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class Component implements Serializable {
    @XmlID
    @XmlAttribute
    protected String uuid;

    @XmlElements({ @XmlElement(type = ComponentO.class), @XmlElement(type = ComponentI.class),
        @XmlElement(type = ComponentIO.class) })
    @XmlElementWrapper(name = "childs")
    protected List<Component> components = new ArrayList<>();
}

public interface IInputOutput extends IInput, IOutput {
}

@XmlRootElement
public class ComponentIO extends Component implements IInputOutput {
}

@XmlRootElement
public class ComponentI extends Component implements IInput {
}

This solution create this kind of xml :

<componentIO uuid="d911479d-597f-4908-ab67-29ee5df5e367">
    <name>a</name>
    <childs>
        <components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
            <name>b</name>
            <childs/>
        </components>
        <components uuid="8a06954c-8e59-4e5b-af9c-c53a103f2f79">
            <name>c</name>
            <childs>
                <components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
                    <name>b</name>
                    <childs/>
                </components>
            </childs>
        </components>
    </childs>
</componentIO>

But, i want this :

<componentIO uuid="d911479d-597f-4908-ab67-29ee5df5e367">
    <name>a</name>
    <childs>
        <components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
            <name>b</name>
            <childs/>
        </components>
        <components uuid="8a06954c-8e59-4e5b-af9c-c53a103f2f79">
            <name>c</name>
            <childs>
                <components reference="9af14b4d-c11c-47fe-9fb9-307da83e30f8"/>
            </childs>
        </components>
    </childs>
</componentIO>

Of course, when I unmarshal the xml file, I want one instance of component "b".

I don't know, I test to use Adapter with no success...anybody have a idea ?

It's the first problem, if we resolv this...another come after ^^

Thanks :)

0 Answers0