Convert JPA entities to JSON!

Paste Spring Boot JPA entities (@Entity, Hibernate) and get an example JSON! Handy for API tests and mock request bodies.
JPA
Result
 

Convert JPA entities to JSON!

Paste Spring Boot JPA @Entity classes and see example JSON in the shape Jackson produces when a controller returns those entities. Field names, @JsonIgnore and @JsonProperty, fields inherited from a @MappedSuperclass, and Java 8 date types are all handled according to Spring Boot's default Jackson setup.

Use it for REST Docs or Swagger examples, Postman request bodies, or to audit which fields leak out when an entity is exposed without a DTO.

How to use

  1. Paste entity classes into the JPA box. Imports and Lombok annotations can stay; include parent classes, related entities and enums so their values are filled.
  2. The class no other class references becomes the root. When entities reference each other, the public class is chosen.
  3. Copy the result into your test or documentation.

Example

Input (Java · JPA)
@MappedSuperclass
public abstract class BaseEntity {
    @Id @GeneratedValue
    private Long id;
    private LocalDateTime createdAt;
}

@Entity
public class Appointment extends BaseEntity {
    private LocalDate visitDate;
    private BigDecimal fee;
    @Enumerated(EnumType.STRING)
    private Status status;
    @ManyToOne(fetch = FetchType.LAZY)
    private Patient patient;

    public enum Status { BOOKED, DONE, CANCELED }
}

@Entity
class Patient extends BaseEntity {
    private String name;
    @JsonIgnore
    private String residentNumber;
    @OneToMany(mappedBy = "patient")
    private List<Appointment> appointments;
}
Output (JSON)
{
  "id": 0,
  "createdAt": "1970-01-01T00:00:00",
  "visitDate": "1970-01-01",
  "fee": 0,
  "status": "BOOKED",
  "patient": {
    "id": 0,
    "createdAt": "1970-01-01T00:00:00",
    "name": "",
    "appointments": []
  }
}

Appointment and Patient reference each other, so the public class Appointment is the root and Patient.appointments is cut to an empty array instead of looping forever. id and createdAt from BaseEntity come first, and residentNumber is gone because of @JsonIgnore. LocalDateTime is an ISO string without an offset, and the enum shows its first constant, "BOOKED".

Supported features

  • static and transient fields and @JsonIgnore fields are skipped, as are names listed in a class-level @JsonIgnoreProperties({"..."}).
  • @JsonProperty("doctor_name") renames the JSON key.
  • When the parent class (@MappedSuperclass or any extends) is in the input, its fields come first.
  • An entity default like private Status status = Status.ACTIVE; or private int visits = 0; shows up as that value, and computed getters with no backing field (public int getAge()) appear as extra keys, just as Jackson would emit them.
  • Date output follows Spring Boot defaults: LocalDate → 1970-01-01, LocalDateTime → 1970-01-01T00:00:00, java.util.Date → 1970-01-01T00:00:00.000+00:00.
  • Numeric wrappers like BigDecimal and Long give 0, UUID an all-zero UUID, and byte[] the base64 string "AA==".
  • List/Set give a one-element array, Map<Long, String> gives an object keyed to match ({"0": ""}), and Optional<T> unwraps to its inner value.
  • Bidirectional associations (@OneToMany with @ManyToOne) are cut with null or an empty array where they loop back.

Use cases

Spring REST Docs and Swagger examples

Generate the JSON for @Schema(example = ...) or documentation snippets straight from the entity, and paste again whenever fields change to keep docs in sync.

Auditing exposed entities

If you return entities without DTOs, check whether fields like passwords or national ID numbers end up in responses. Fields in the output are the ones Jackson would serialize.

MockMvc request bodies

Use the output as the skeleton for mockMvc.perform(post("/appointments").content(...)), removing the generated id and timestamps before filling in values.

Notes and limitations

  • Real Jackson recurses forever (StackOverflowError) on bidirectional associations. If the output looks cut off, that is your cue for @JsonManagedReference/@JsonBackReference, @JsonIgnore or a DTO.
  • The JPA @Transient annotation is not ignored by Jackson by default, so such fields stay in the output; only fields with the Java transient keyword are removed.
  • FetchType.LAZY associations can fail to serialize as Hibernate proxies in practice; the output assumes everything is loaded.
  • Fields whose class is not in the input appear as null, and @Column constraints such as nullable or length are not applied.

FAQ

Should dates really be strings and not arrays like [2024,1,1]?

Spring Boot disables WRITE_DATES_AS_TIMESTAMPS, so LocalDateTime is written as an ISO string. A hand-built ObjectMapper with only JavaTimeModule registered may write arrays instead.

Do all fields show up even without Lombok @Getter?

The tool works from field declarations. Real Jackson serializes through getters (or public fields) by default, so private fields without getters may be missing from actual responses.

Can I paste MongoDB @Document classes too?

They follow the same Jackson rules, but MongoDB-specific caveats like ObjectId and @Field are covered on the Spring Data MongoDB to JSON page.