Q:

Jaxb, avoid duplicate xml tag

I'm facing a problem with my implementation of Jaxb java classes. My xml response should be like:
 <rootElement attr1="value1" attr2="value2">
      <child> childValue </child>
 </rootElement>

this is my java classes:
 @XmlRootElement
 public class RootElement {
     private String attr1;
     private String attr2;
     private Child child;

     @XmlAttribute
     public String getAttr1() {
         return attr1;
     }

     public void setAttr1(String attr1) {
         this.attr1 = attr1;
     }

     @XmlAttribute
     public String getAttr2() {
         return attr2;
     }

     public void setAttr2(String attr2) {
         this.attr2 = attr2;
     }

     public void setChild(Child c) {
         child = c;
     }

     @XmlElement
     public Token getChild() {
         return child;
     }
 }

and this is Child:
 public class Child {

     private String child;

     public Child() {

     }

     public void setChild(String child) {
         this.child = child;
     }

     public String getChild() {
         return child;
     }

 }

I obtain this xml:
 <rootElement attr1="value1" attr2="value2">
      <child><child>childValue</child></child>
 </rootElement>

What's wrong?

A:

The first <child> is produced for child variable of RootElement class.
The second <child> is produced for child variable of Child class.  
If you can make sure there is only one mapping in Child class, you can add @XmlAnyElement to child variable. JAXP will not produce second <child> element.
public class Child {

    @XmlAnyElement
    private String child;

    public Child() {
    }

    public void setChild(String child) {
        this.child = child;
    }
    public String getChild() {
        return child;
    }
}

