XML to Java Converter

Turn a sample XML document into Java model classes, a record, or a Lombok annotated POJO.

XML
Java
Runs locally in your browser

About the XML to Java Converter

Hand writing a Java model to match an XML message is mechanical work that a machine should do. Paste a representative document here and you get one class per distinct element shape, with wrapper types chosen so that a missing value can be represented: Integer and Double rather than the primitives, since XML fields go absent far more often than a schema suggests.

Three output styles cover the common house rules. The POJO style writes private fields with full getters and setters, which is what older codebases and most XML binding frameworks expect. The record style produces a single compact line per type and suits immutable value objects in modern services. The Lombok style keeps the fields and adds @Data, leaving the boilerplate to the annotation processor.

Turning on JAXB annotations adds @XmlRootElement to the top type and @XmlElement to each field, with the original tag name preserved in the annotation so a Java field renamed to camel case still binds to the right element. That matters because XML tags are frequently written in lower case with hyphens, which are illegal in Java identifiers, so the names are converted while the annotation keeps the mapping honest. Set a package name to get the declaration at the top of the file. For a starting point in another language, try XML to C# or XML to Go.

How to use

  1. Paste an XML sample containing every field you want in the model.
  2. Choose a class style: POJO for binding frameworks, record for immutable values, Lombok if your project uses it.
  3. Tick Add JAXB annotations when the classes will be bound to XML rather than JSON.
  4. Type a package name, then copy the classes into your source tree.

Common questions

Why are the types Integer and Double instead of int and double?
Wrapper types can hold null, which matters because an element may be missing from a real message even when your sample includes it.
Do all the classes go in one file?
The output is one block of text with several classes. Java wants one public class per file, so split them or nest them as static classes.
How is a hyphenated tag name handled?
It becomes a camel case field name, and the JAXB annotation records the original tag so binding still works.
Can it read an XSD schema instead?
No. It infers the model from a sample document. For a formal schema, a JAXB compiler such as xjc is the right tool.