title: How to serialize single-valued @Data object using Jackson without nesting (e.g. {"id":123}, not {"id":{"value":123}})?
body: <p>I'm planning to use Lombok for creating hundreds of classes that are based on "value object" pattern as follows:</p>
  
  <pre><code>@Data
  public final class SomeId implements Serializable {
      private final long value;
  }
  </code></pre>
  
  <p>And I want to use these classes for JSON serialization powered by Jackson. for example, consider a DTO class as follows:</p>
  
  <pre><code>public class SomeDTO {
      SomeId id;
      public SomeId getId() {
          return id;
      }
  }
  </code></pre>
  
  <p>I want that DTO class to be serialized as something like <code>{"id":123}</code>, but Jackson produces something like <code>{"id":{"value":123}}</code>, which comes with unnecessary nested object with a field named <code>value</code>. i.e. a testcase expresses my requirement:</p>
  
  <pre><code>public class SomeDTOTest {
      @Test
      public void serializationTest() throws Exception {
          SomeDTO dto = new SomeDTO();
          dto.id = new SomeId(123);
  
          String serialized = new ObjectMapper().writeValueAsString(dto);
  
          System.out.println(serialized);             // {"id":{"value":123}}
          assertThat(serialized, is("{\"id\":123}")); // I want {"id":123} instead!
      }
  }
  </code></pre>
  
  <p>I know putting <code>@JsonValue</code> annotation to every <code>getValue()</code> method in <code>SomeId</code> classes would be a solution, but I can't do it because there is no actual definition of <code>@Data</code> classes because Lombok automatically creates it.</p>
  
  <p>Creating actual <code>getValue()</code> method annotated as <code>@JsonValue</code> for every classes by hand might be another solution but it means creating tons of boilarplate code.</p>
  
  <p>How do I achieve this requirement without boilerplate code?</p>