YAML to Java
Paste YAML and instantly generate matching Java POJO classes with inferred field types for nested objects and lists.
Example
Input YAML:
name: Ada
age: 36
skills:
- Java
- YAML
Generated Java:
import java.util.List;
public class Root {
private String name;
private long age;
private List<String> skills;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public long getAge() { return age; }
public void setAge(long age) { this.age = age; }
public List<String> getSkills() { return skills; }
public void setSkills(List<String> skills) { this.skills = skills; }
}How it works
The tool parses your YAML with js-yaml into a value, infers a Java type model (including nested classes and List element types), then emits clean POJO class definitions. The root type is named Root.
Good to know
YAML to Java takes a YAML document and generates matching Java POJO (plain old Java object) classes, complete with private fields, getters, and setters. It reads the structure of your YAML, infers a Java type for every value, builds separate classes for nested mappings, and types out lists with the right element type. It is aimed at Java developers who need to model config files, API payloads, or fixture data as strongly typed classes without writing the boilerplate by hand.
Reach for it when you have a sample YAML response or a configuration file and want a starting point for deserialization with Jackson, SnakeYAML, or a similar library. It is also handy for quickly sketching a domain model from example data, or for converting a YAML schema into Java during a migration. Because everything runs in your browser, you can paste internal or sensitive config without it leaving your device.
To read the output, start at the class named Root, which represents the top level of your document. Each nested object becomes its own class named after its key, and a list of objects produces a class named from the singularized key (for example, a "projects" list yields a Project class). Pay attention to the inferred scalar types: whole numbers become long, decimals become double, and any null or empty value falls back to Object so the code still compiles.
One practical caveat is that types are inferred only from the example you paste, so a single sample drives every decision. If a numeric field is sometimes a whole number and sometimes a decimal across real records, or a list mixes shapes, the inference will collapse to Object or pick the type from the values it actually sees. Feed it a representative example, then adjust field types (for instance long to int, or Object to a concrete class) by hand before using the result in production.
Frequently asked questions
How are nested objects and lists handled?
Each nested mapping becomes its own Java class (named from the key), and YAML sequences become Listwith the element type inferred from the items. Lists of objects generate a class for the element type using a singularized key name.
How does it choose Java types for scalars?
Integers map to long, decimals to double, true/false to boolean, text to String, and null or empty values to Object so the generated code always compiles.
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 YAML to Java add Jackson or annotations to the generated classes?
No. The tool emits plain POJOs with fields, getters, and setters only. You would add annotations such as @JsonProperty or configure SnakeYAML mapping yourself if your deserializer needs them.
Why are integer fields generated as long instead of int?
The tool maps whole numbers to long to avoid overflow on large values, and only uses long when the integer fits within roughly nine quadrillion. You can safely change long to int by hand for fields you know are small.
What Java type is used for an empty list in YAML?
An empty YAML sequence becomes List<Object> because there are no items to infer an element type from. Replace Object with the intended type once you know what the list will hold.
How are duplicate or repeated class names handled?
If two nested objects would produce the same class name, the tool appends a number to keep names unique, for example Type and Type2. This prevents compile errors from clashing class declarations.
Can it convert a YAML file whose top level is a list?
Yes. When the root of the document is a sequence, the tool wraps it in a Root class with a single field named items holding the list, and infers the element type from the array contents.
Does this tool work offline?
Yes, once the page has loaded it runs entirely client-side and needs no network connection. Your YAML is parsed and converted in the browser and is never uploaded.
How does it pick getter names for boolean fields?
Boolean fields get an is-prefixed accessor, such as isActive(), following common JavaBean convention, while all other types use a get prefix like getName().
What happens if my YAML is invalid?
The tool reports a YAML error with the parser's message and clears the output instead of generating classes. Fix the syntax in the input and it will reconvert automatically as you type.
Related tools