Lombok builder pattern with jackson JsonProperty

Your mapper need to have a means of creating User class.

You could use constructor:

@NoArgsConstructor
@AllArgsConstructor
@Getter
@ToString
@Builder
class User {
  @JsonProperty("user_name")
  @NonNull
  private String userName;

  private int userId;
}

... or point it to builder as per Tomasz Linkowski's answer


You get this error because Jackson doesn't know how to map user_name to any of your UserBuilder fields.

You need @JsonProperty("user_name") on the userName field of UserBuilder too, like that:

@JsonPOJOBuilder(withPrefix = "")
public static class UserBuilder {

    @JsonProperty("user_name")
    @NonNull
    private String userName;
}