Henrik
Henrik

Reputation: 1807

JAXB - Xml Annotation in Parent class to only set a specific field in child class

Let's say we have a person who has a Child and I want to annotate the object reference to only map a specific field in the Child class to the parent object. Which annotation will I be using then?

The xml looks like this:

<Person>
    <Child>Peter</Child>
</Person>

POJOs looks like this:

public class Person {
    @XmlElement(name = "Child")
    private Child child;
}

public class Child {
    @XmlElement(name = "Child")
    private String name;
}

But this doesnt work at all, I've also tried XmlElementRef etc.

Upvotes: 1

Views: 520

Answers (1)

sidgate
sidgate

Reputation: 15234

public class Child {
    @XmlValue
    private String name;
}

Upvotes: 1

Related Questions