JSON to Java Converter

Generate Java POJO classes from JSON data. Paste your JSON and configure options:

Loading...
Loading...

Generate Java Classes from JSON

This tool automatically generates Java class definitions from your JSON data. It infers types from values, handles nested objects, and supports popular libraries like Lombok, Jackson, and Gson.

Output Options

Standard POJO with Lombok

Using Lombok's @Data annotation eliminates boilerplate by auto-generating getters, setters, toString, equals, and hashCode:

@Data
public class User {
    @JsonProperty("user_name")
    private String userName;
    
    private Integer age;
    private List<String> roles;
}

Java 16+ Records

Records are immutable data classes with concise syntax. Ideal for DTOs:

public record User(
    @JsonProperty("user_name") String userName,
    Integer age,
    List<String> roles
) {}

Jackson vs Gson

FeatureJacksonGson
Annotation@JsonProperty@SerializedName
SpeedFaster for large payloadsSimpler for small data
Spring BootDefault choiceRequires configuration

Type Inference

The converter maps JSON types to Java:

JSONJavaNotes
stringString
integerInteger / LongLong for values > 2.1B
decimalDouble
booleanBoolean
arrayList<T>Type from first element
objectNested classSeparate class generated
nullObject

Example Conversion

Input JSON:

{
  "id": 1,
  "username": "john_doe",
  "profile": {
    "firstName": "John",
    "age": 30
  }
}

Generated Java (with Lombok + Jackson):

package com.example.model;

import java.util.List;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonProperty;

@Data
public class Root {
    private Integer id;
    
    private String username;
    
    private Profile profile;
}

@Data
public class Profile {
    @JsonProperty("firstName")
    private String firstName;
    
    private Integer age;
}

Using Generated Classes

With Jackson

ObjectMapper mapper = new ObjectMapper();

// Deserialize
String json = getJsonFromApi();
Root data = mapper.readValue(json, Root.class);

// Serialize
String output = mapper.writeValueAsString(data);

With Gson

Gson gson = new Gson();

// Deserialize
Root data = gson.fromJson(json, Root.class);

// Serialize
String output = gson.toJson(data);

Best Practices

  • Use Lombok — Eliminates boilerplate getters/setters
  • Use wrapper typesInteger instead of intto handle nulls
  • Add validation — Consider adding @NotNull,@Size annotations manually
  • Use records for DTOs — Immutable, thread-safe, less code

Related Tools

Frequently Asked Questions

Should I use Lombok or write getters/setters?

Lombok is recommended for most projects — it reduces boilerplate significantly. However, some teams prefer explicit code for debugging or IDE support reasons.

When should I use Records vs Classes?

Use records for immutable data transfer objects (DTOs). Use classes when you need mutability, inheritance, or complex behavior.

How do I handle null values?

The converter uses wrapper types (Integer, Boolean) which can be null. For primitives that shouldn't be null, change toint, boolean manually.