2

I'm trying to get that XML:

<person>
    <foo>thing</foo>
    <bar>other</bar>
</person>

from that code

public class Person {
    private InnerThing in;
}

public class InnerThing {
    private String foo;
    private String bar;
}

with JAXB java annotations.

By default, I get

<person>
    <innerThing>
        <foo>thing</foo>
        <bar>other</bar>
    </innerThing>
</person>

How can I skip the InnerThing tag with just annotations?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Esteban
  • 21
  • 1

1 Answers1

2

You could use EclipseLink JAXB (MOXy)'s @XmlPath annotation to solve this problem (I'm the MOXy tech lead):

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Person {

    @XmlPath(".")
    private InnerThing in;

}

For More Information:

bdoughan
  • 147,609
  • 23
  • 300
  • 400