Roman T
Roman T

Reputation: 2000

Jackson2 and Lombok @Builder

Given I have the POJO:

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class SomeResponse {
  private String author;
  private String authorTitle;
  private String teaser;
  private String text;
  private Long lastModified;
  private Long created;
  private Integer rating;

  private Optional<Markdown> markdown;
  private Optional<Integer> wordCount;
}

When I try to use the POJO in such normal Jackson construction:

restTemplate.getForObject(urlTemplate, SomeResponse.class,      
      productId.toString(), siteId.toString());

I get an exception, because there are private ctor in the SomeResponse class due to Lombok @Builder annotation.

How can I make it works without deleting Lombok @Builder annotation?

Upvotes: 1

Views: 638

Answers (1)

Roel Spilker
Roel Spilker

Reputation: 34452

Also add @AllArgsConstructor and @NoArgsConstructor, possible with the right access values. See the documentation for appropriate parameters.

Disclosure: I am a lombok developer.

Upvotes: 2

Related Questions