Category · 1 tool · 1 guide
Code generators
Much of the code developers write is predictable boilerplate: data classes that mirror an API response, builders, mapping code, configuration files. Writing it by hand is slow and error-prone. A field name typed slightly differently from the JSON key, a number declared as int when the API sends values above two billion, or a nested object that was skipped will compile fine and fail only at runtime.
Code generators take a real example or a schema and produce that boilerplate in seconds. Starting from an actual API response means the generated types match what the server really sends, including nested objects, arrays and awkward key names. You still review and adjust the result, but you start from something correct instead of an empty file.
The tools here generate code from data you paste. Since that data is often a real API response with customer information, generation runs entirely in your browser and nothing is uploaded.
Tools in this category
Common tasks
- Model a third-party API responsePaste a real response to generate Java types for it, then adjust names and nullability.
- Choose between POJOs, Lombok and recordsUnderstand the trade-offs and how Jackson maps JSON to each style.
- Clean up the sample JSON firstFormat and validate the payload so the generator sees every field and correct types.
- Format the generated classesRun the output through a Java formatter to match your project's indentation and line width.
- Generate deployment boilerplateCreate a Dockerfile for the service that uses the generated models.
Key concepts
- POJO
- A plain old Java object: private fields with getters, setters and a no-argument constructor. It works with every framework but needs a lot of boilerplate.
- Lombok
- An annotation processor that generates getters, setters, constructors and builders at compile time from annotations such as @Data and @Builder, keeping source files short.
- Type inference from samples
- A generator guesses types from example values. One sample cannot show that a field is sometimes null or sometimes a decimal, so check fields that may vary.
- @JsonProperty
- A Jackson annotation that maps a JSON key to a Java field with a different name, needed for keys with hyphens, spaces or names that are Java keywords.
- Wrapper vs primitive types
- Integer and Boolean can be null, so they represent missing JSON fields safely. int and boolean default to 0 and false, which hides missing data.
Best practices
- Generate from several real responses or a schema, not just one sample, so optional and nullable fields are captured.
- Use Long for IDs and BigDecimal for money; numeric types guessed from a sample are often too small or imprecise.
- Treat generated code as a starting point: rename classes, add validation and remove fields you do not need.
- Configure Jackson to ignore unknown properties so new fields from the API do not break deserialisation.
- Regenerate and diff when an API changes instead of hand-patching models.