Skip to content
UniKit

JSON to Java

Generate Java POJOs from a JSON sample: nested static classes, List types, boxed nullable fields, optional Jackson annotations and four naming conventions.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Options
Generated Java
package com.example.model;

import java.util.List;

public class Root {
    public int id;
    public String name;
    public boolean isActive;
    public double score;
    public RootOwner owner;
    public List<String> tags;
    public List<RootItems> items;
    public Object meta;

    public static class RootOwner {
        public String name;
        public Object email;
    }

    public static class RootItems {
        public String sku;
        public double price;
        public String note;
    }
}

Summary: Types 3 · Fields 13 · Name clashes 0

What this tool does

  • Build Spring / Jackson request and response models from a JSON sample instead of hand-writing fields and boilerplate.
  • Tell "the field was missing" apart from "the value is zero" by letting nullable fields become wrapper types (Integer, Double, Boolean).
  • Nested objects are emitted as public static classes inside the root class, so a single .java file holds the whole model — matching Java's one-public-class-per-file rule.
  • When a generated field name differs from the JSON key, switch on @JsonProperty and the original key is written into the annotation so Jackson keeps mapping it.

Example

Input

{"id":1,"name":"UniKit","tags":["a","b"]}

Output

package com.example.model;

import java.util.List;

public class Root {
    public int id;
    public String name;
    public List<String> tags;
}

Arrays always map to List<T> and nullable slots are boxed to Integer / Double / Boolean; the java.util.List import only appears when the model actually contains an array.

Frequently asked questions

Why are nested objects static classes instead of separate files?

A .java file may only contain one public class, so nested objects are generated as public static classes inside the root class and the whole model compiles from one file. To split them up, cut each static class into its own file named after the class.

Why is a field Integer instead of int?

Because the key is null in some array elements, or missing from some of them, and a primitive int cannot represent "no value" — those slots get boxed. If the key is only ever null in the sample it carries no type information and degrades to Object instead of Integer. Change it back to int by hand when the field is guaranteed to be present.

When does @JsonProperty get added?

Only when the option is enabled and the generated field name differs from the original JSON key — for example after a naming convention rewrite or because the key contains illegal characters. Matching names get no annotation.

What if a JSON key is a Java keyword?

Keywords such as class, static or default get an underscore appended (class becomes class_) so the code compiles. Enable @JsonProperty to write the original key back into an annotation.

Is my JSON uploaded anywhere?

No. Parsing and code generation run entirely in your browser, no network request is made, and it works offline.

Keywords:jsonjavapojojacksonjsonpropertyjson to javaJSON 转 Java实体类嵌套类代码生成

Related tools