JAXB - How to marshal java object without header

Viewed 9678

I'm trying to marshal a java object but I want to remove the header that Jaxb is introducing.

Object:

@XmlRootElement
public class FormElement implements Serializable {
    private String id;
    private String name;
    private Integer order;
}

Expected output:

<element>
    <id>asd</id>
    <name>asd</name>
    <order>1</order>
</element>

My output:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<formElement>
  <id>asd</id>
  <name>asd</name>
  <order>1</order>
</formElement>

My marshal method:

public String marshal() {
        JAXBContext context;
        try {
            context = JAXBContext.newInstance(FormElement.class);
            Marshaller marshaller = context.createMarshaller();
            StringWriter stringWriter = new StringWriter();
            marshaller.marshal(this, stringWriter);
            return stringWriter.toString();
        } catch (JAXBException e) {
        }
        return null;
    }

How can I remove it?

Thanks in advance.

1 Answers
Related