Convert JSON input into ready-to-use Java POJO classes for Spring Boot RESTful applications.
In your Spring Boot project, create a package such as:
src/main/java
└── com.example.demo
├── controller
├── service
├── repository
└── model
Create a Java class under the model or dto package.
src/main/java/com/example/demo/model/Employee.java
Click the Copy button above. Open the Java file in Eclipse, IntelliJ IDEA or another IDE and paste the generated code.
Make sure the package name matches the directory.
package com.example.demo.model;
@RestController
@RequestMapping("/api/employees")
public class EmployeeController {
@PostMapping
public Employee createEmployee(
@RequestBody Employee employee) {
System.out.println(employee);
return employee;
}
}
POST http://localhost:8080/api/employees
Content-Type: application/json
{
"id": 101,
"name": "John",
"salary": 75000,
"active": true
}
Spring Boot uses Jackson to deserialize the incoming JSON into the generated Java POJO.
JSON ↓ Jackson ↓ Employee POJO ↓ REST Controller ↓ Service ↓ Repository
src/main/java/com/example/demo/dto/EmployeeRequest.java src/main/java/com/example/demo/dto/EmployeeResponse.java