title: Using Jackson to deserialize with Lombok builder
body: <h3>The Question</h3>
  <p><a href="https://projectlombok.org/features/Builder" rel="noreferrer">Lombok</a>'s <code>@builder</code> annotation creates a <a href="https://en.wikipedia.org/wiki/Builder_pattern" rel="noreferrer">builder-class</a> for a class. To support deserialization of json items (using <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html" rel="noreferrer">Jackson's ObjectMapper</a>), I've added the following annotations:</p>
  <pre class="lang-java prettyprint-override"><code>@Builder
  @JsonDeserialize(builder = Item.ItemBuilder.class)
  @JsonPOJOBuilder(withPrefix=&quot;&quot;)
  public class Item {
      @Getter
      String partitionvalue;
  }
  </code></pre>
  <p>This is based on the <code>@Jacksonized</code> <a href="https://projectlombok.org/features/experimental/Jacksonized" rel="noreferrer">documentation</a>. On the usage of the deserializer, upon a json file which is stored in <a href="https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3.html" rel="noreferrer">AWS S3 bucket</a> and its content is simply: <code>{&quot;partitionvalue&quot;: &quot;test&quot;}</code>, my code is:</p>
  <pre class="lang-java prettyprint-override"><code>AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
              .withCredentials(new DefaultAWSCredentialsProviderChain())
              .withRegion(region)
              .build();
  S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucket, key));
  Item item = objectMapper.readValue(s3Object.getObjectContent(), Item.class);
  </code></pre>
  <p>However when running on a json file that  Jackson fails with the message:</p>
  <pre class="lang-sh prettyprint-override"><code>Unrecognized field &quot;partitionvalue&quot; (class com.example.Test$TestBuilder),
   not marked as ignorable (0 known properties: ])
   at [Source: com.amazonaws.services.s3.model.S3ObjectInputStream@2ca47471; line: 1, column: 21] (through reference chain: com.example.TestBuilder[&quot;partitionvalue&quot;])
  </code></pre>
  <h3>Extra Details</h3>
  <ul>
  <li><p>Using @<code>Jacksonized</code> annotation directly didn't work as well, and since it is lombok-experimental I used the annotations I needed to use with builder directly.</p>
  </li>
  <li><p>I verified that Lombok will do what I expect of a builder class by using &quot;delombok&quot; option in the Lombok IntelliJ plugin:</p>
  </li>
  </ul>
  <pre class="lang-java prettyprint-override"><code>public class Item {
      String partitionvalue;
      Item(String partitionvalue) {
          this.partitionvalue = partitionvalue;
      }
      public static ItemBuilder builder() {
          return new ItemBuilder();
      }
      public String getPartitionvalue() {
          return this.partitionvalue;
      }
      public static class ItemBuilder {
          private String partitionvalue;
          ItemBuilder() { }
          public Item.ItemBuilder partitionvalue(String partitionvalue) {
              this.partitionvalue = partitionvalue;
              return this;
          }
          public Item build() {
              return new Item(partitionvalue);
          }
          public String toString() {
              return &quot;Item.ItemBuilder(partitionvalue=&quot; + this.partitionvalue + &quot;)&quot;;
          }
      }
  }
  </code></pre>
  <ul>
  <li>Without the <code>@Builder</code> annotation (and with adding <code>@NoArgsConstructor</code> +  <code>@AllArgsConstructor</code> + <code>@Setter</code>) it worked fine, so the problem isn't with the file from the S3 bucket or the way it is parsed.</li>
  </ul>