XML to Java Converter

Turn XML into Java classes with fields, getters, setters and JAXB or Jackson annotations.

Add XML and click Generate to see the code here.

How XML to Java Converter works

Generates Java classes from XML. Each element with child tags or attributes becomes a class with private fields, getters and setters. All classes go in one file, with the class for the root element first.

The whole document is read first, so each field gets a type that fits every value: long for whole numbers, double for decimals, boolean for true or false and String for the rest. Tags that repeat become List fields. Annotations map each field back to its tag or attribute, so you can read the XML with JAXB or Jackson.

Input to XML to Java Converter

  • Paste or type XML into the input box, or upload a .xml or .txt file. Click Generate to run it.
  • Class name: the name of the main class. Leave it empty to use the root tag name.
  • Package: an optional package line, like com.example.model.
  • Annotations: JAXB (jakarta), JAXB (javax), Jackson XML or None. Change any option and the code updates right away.

Output from XML to Java Converter

  • Java code with the package line, the imports you need and one class for each kind of element.
  • With JAXB, fields get @XmlElement, @XmlAttribute or @XmlValue. With Jackson XML, they get @JacksonXmlProperty or @JacksonXmlText.
  • Fields that can be empty or missing use Long, Double or Boolean in place of long, double or boolean.
  • Copy it or download it as a .java file named after the main class.