JSON to Kotlin
Review nullability and Kotlin data class structure quickly.
JSON to Java Converter: Lombok & Records
Generate Java DTOs with Lombok or records, review Jakarta or javax validation, and copy the result. JSON conversion runs locally in your browser.
Input
Generate Java DTOs with Lombok or records, review Jakarta or javax validation, and copy the result. JSON conversion runs locally in your browser.
{
"orderId": "ORD-2026-001",
"status": "PAID",
"amount": 12900,
"customer": {
"name": "Lee",
"email": "lee@example.com"
}
}
Output
public class OrderResponse {
private final String orderId;
private final String status;
private final Integer amount;
private final Customer customer;
}
Explanation
DTOs turn ad hoc payload handling into explicit contracts that compilers, reviewers, and tests can all validate.
Select Record for an immutable DTO draft. This adapted Java 17 example preserves order_id with JsonProperty and deliberately uses BigDecimal for money; sample-based inference does not decide monetary precision for you. Jackson 2.12+ supports records. In Spring Boot 3, use your injected ObjectMapper so application modules and policies are retained.
Validation annotations are separate from deserialization: call a Validator or use the validated controller boundary when you need constraints enforced. Add missing, null and unknown-field fixtures under your actual ObjectMapper configuration before adopting the model.
Input fixture
{"order_id":"ORD-42","amount":12.50}
Adapted application model
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
public record OrderResponse(
@JsonProperty("order_id") String orderId,
BigDecimal amount
) {}
Verification in your project
// Jackson 2.12+ with record support, Java 17+.
// In Spring Boot 3, inject the configured ObjectMapper.
import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
var mapper = new ObjectMapper();
var order = mapper.readValue(
"{\"order_id\":\"ORD-42\",\"amount\":12.50}", OrderResponse.class);
if (!"ORD-42".equals(order.orderId()) ||
order.amount().compareTo(new BigDecimal("12.50")) != 0) {
throw new AssertionError("Unexpected API mapping");
}
Before choosing Lombok annotations or validation constraints, decide what the class represents. An inbound request, a partner API response, an internal event, and a domain command may share the same fields but require different nullability and compatibility policies. External response DTOs often need to tolerate missing data, while internal commands can reject incomplete input early.
Keeping that boundary explicit also prevents transport details from leaking into domain code. Generate the response shape first, place it near the integration client, and map it into a domain model when business rules become important. This separation makes upstream API changes easier to absorb without rewriting unrelated service logic.
Strings, booleans, objects, and populated arrays usually map cleanly, but dates, money, identifiers, empty arrays, and null values remain ambiguous. A timestamp-looking string may become Instant or OffsetDateTime. A monetary decimal usually deserves BigDecimal, and a large identifier may need Long even when the sample value is small.
Nested objects can begin as static inner classes because that keeps the generated draft easy to scan. Move them into separate files when they are reused, acquire behavior, or make the parent DTO difficult to review. For snake_case keys, keep idiomatic camelCase Java fields and preserve the original wire name with JsonProperty where necessary.
Jackson requirements depend on the construction style. A Lombok class may need a compatible constructor, while a Java record offers a concise immutable representation on modern runtimes. Validation annotations describe accepted input; they should not be copied blindly onto third-party responses that your service does not control.
Treat the generated output as a reviewable draft. Confirm constructor behavior, unknown-property handling, enum fallbacks, date modules, and validation groups against the actual Spring and Jackson configuration used by the project. These checks are small compared with debugging a deserialization failure after deployment.
Compile the DTO in the target project and deserialize representative fixtures in a focused test. Include missing fields, explicit nulls, empty collections, maximum numeric values, and at least one unexpected enum value. This verifies the contract instead of only verifying that the generated source looks plausible.
Finally, keep the sample JSON beside the test or API documentation that explains it. When an upstream payload changes, a JSON diff and a DTO diff in the same pull request give reviewers enough context to judge compatibility quickly.
Related Tools
These internal links connect the language page to adjacent tools used in the same API workflow.
Review nullability and Kotlin data class structure quickly.
Turn API payloads into TypeScript interfaces for frontend work.
Format sample payloads before sending them back into the converter.
Compare generated classes with schema-oriented documentation output.