Home

@Builder and Constructor Cause Jackson Deserialization Failure

Li

Li Wei

August 22, 20252 min read

@Builder and Constructors Causing Jackson Deserialization Failure

Background

Project/Module: Some service interface request object

Use case: Simplify object construction with Lombok @Builder

Trigger condition: The object needs to be deserialized from JSON to an object using Jackson

Issue

Error message: Cannot construct instance of xxx.BlacklistAddReq (no Creators, like default constructor, exist)

Actual behavior: Jackson cannot create the object, resulting in deserialization failure

Expected behavior: JSON should be converted to a BlacklistAddReq object successfully

Reproduction Steps

  • Define the object:
  • Attempt deserialization with Jackson:
  • Result: After the API call, deserialization fails with a missing no‑args constructor error.

Root Cause

When the @Builder annotation is used, Lombok automatically generates an all‑args constructor, but its access modifier is private. It no longer generates a no‑args constructor (unless you explicitly add @NoArgsConstructor).

Jackson’s deserialization process by default creates an instance via a no‑args constructor and then injects fields via setters, or it can use a visible all‑args constructor.

The problem is the missing no‑args constructor; the all‑args constructor is private and therefore invisible, so Jackson cannot instantiate the object.

Solutions

Solution 1 (recommended): Manually add constructors, explicitly adding @NoArgsConstructor and @AllArgsConstructor, to avoid @Builder overwriting the default constructor.

Solution 2: Use @Jacksonized (recommended, Lombok 1.18.14+), which automatically adapts the class for Jackson without needing to maintain constructors manually.

Lessons Learned

When using @Builder, keep in mind:

  • A no‑args constructor is not generated by default.
  • The all‑args constructor is set to private, which Jackson cannot use.

When working with Jackson, it is advisable to use @Jacksonized to reduce manual maintenance. Pay special attention to constructor visibility when combining Lombok annotations with serialization frameworks.

References


Originally written by Li Wei (李唯_) and published in Chinese on 后端技术栈全书 (Full-Stack Backend Engineering). Translated and adapted for DriftSeas with permission.

Keep reading

More related articles from DriftSeas.