XML to Java
Turn any XML document into ready-to-use Java POJO classes with inferred field types and nested structures.
Example
Input XML:
<person id="7">
<name>Ada</name>
<age>36</age>
</person>
Generated Java:
public class Root {
private String name;
private long age;
private long id;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
// ... getters/setters for age, id
}How it works
Paste XML in the input pane; the tool parses it with the browser DOMParser, infers a type model from element/attribute values, and emits Java classes (root type named Root) with private fields plus getters and setters.
Good to know
XML to Java takes a raw XML document and generates matching Java POJO classes, complete with private fields, getters, and setters. It is aimed at Java developers who need to map an XML payload, config file, or API response into typed objects without hand-writing boilerplate. Because everything runs in the browser via the native DOMParser, you can paste sensitive or internal XML without it ever leaving your machine.
Reach for it when you are wiring up a SOAP response, a legacy config schema, or any XML feed and want a fast scaffold for JAXB-style or plain data classes. Field types are inferred from the actual values you paste: integers become long, decimals become double, true/false becomes boolean, and anything else falls back to String. Element attributes are flattened into fields on the same class, and a nested element becomes its own class with a capitalized name.
Read the output starting from the class named Root, which represents your document's top-level element. Repeated child elements with the same tag name are collapsed into a List<Type>, and a java.util.List import is added automatically only when a list actually appears. Note that the type guess reflects only the sample you provide, so a field that happens to hold a numeric-looking string (like a zip code or version) may be typed as long or double instead of String.
A practical tip: feed it the most complete, representative XML you have. A single short example can cause the inferrer to pick a too-narrow type or miss optional fields, since it only sees what is present in your input. After generating, review and adjust types by hand where the data is ambiguous, and rename the generated Root and nested class names to fit your domain.
Frequently asked questions
How are XML attributes handled?
Attributes on an element become fields on that element's Java class, using the attribute name as the field name and the value to infer the type (long, double, boolean, or String).
How does it decide a field should be a List?
When an element has multiple child elements with the same tag name, that tag is treated as a repeated element and emitted as a List of the inferred element type (for example Listor a nested class).
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
Does XML to Java add JAXB or Jackson annotations?
No. It generates plain POJOs with private fields plus getters and setters, without JAXB (@XmlRootElement) or Jackson (@JsonProperty) annotations. You would add binding annotations yourself if your serialization library needs them.
What Java type does it use for integers versus decimals?
Whole numbers are inferred as long and numbers with a decimal point are inferred as double. Inside generic List types these are boxed to Long and Double; boolean values map to boolean (or Boolean in a list), and everything else becomes String.
How does it name the generated classes?
The top-level element is always emitted as a class named Root, and each nested element becomes a class named after its tag with the first letter capitalized. You can rename these freely after copying the output.
Does it handle XML namespaces or prefixes?
Namespace-prefixed tags and attributes are read using their literal names, and any characters that are invalid in Java identifiers (such as colons) are replaced with underscores. There is no special namespace mapping, so prefixed names are sanitized rather than resolved.
Why does my repeated element show up as a List but a single one does not?
The tool decides a field is a List only when it sees two or more child elements sharing the same tag name in your input. If an element appears just once it is treated as a single value, so include multiple instances if a field should always be a collection.
Will the generated field types always be correct?
Not necessarily, because types are guessed from the values in the XML you paste. A value like an ID or postal code made only of digits may be inferred as long even if you intend it to be a String, so review and adjust types after generating.
Can I convert text inside elements that also have attributes?
When an element has both attributes and child elements, the attributes are added as fields alongside the children. If an element has only text plus attributes, the attributes become fields but the inner text content is not captured as a separate field.
Is XML to Java free and does it work offline?
Yes. The tool is free with no sign-up or limits and runs entirely client-side, so once the page has loaded it continues to work without an internet connection and your XML stays on your device.
Related tools