Lombok @SuperBuilder example with json annotations









up vote
8
down vote

favorite
3












can someone please provide me a working example with the lombok @SuperBuilder experimental annotation?



I can't get it running and there is no code example as documentation available.



Currently my code looks like this:



Superclass:



@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
@JsonSubTypes.Type(value = SubA.class),
@JsonSubTypes.Type(value = AnotherSub.class)
)
@Getter
@Accessors(fluent = true, chain = true)
@SuperBuilder
public abstract class AbstractA

@JsonProperty
protected final String superProperty;



And the subclass:



@Getter
@EqualsAndHashCode(callSuper = true)
@Accessors(fluent = true, chain = true)
@SuperBuilder
@JsonDeserialize(builder = SubA.SubABuilder.class) // class not found?
@JsonTypeName("SubA")
public class SubA extends AbstractA

@JsonProperty
private final String fieldA;



Thanks










share|improve this question

























    up vote
    8
    down vote

    favorite
    3












    can someone please provide me a working example with the lombok @SuperBuilder experimental annotation?



    I can't get it running and there is no code example as documentation available.



    Currently my code looks like this:



    Superclass:



    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
    @JsonSubTypes(
    @JsonSubTypes.Type(value = SubA.class),
    @JsonSubTypes.Type(value = AnotherSub.class)
    )
    @Getter
    @Accessors(fluent = true, chain = true)
    @SuperBuilder
    public abstract class AbstractA

    @JsonProperty
    protected final String superProperty;



    And the subclass:



    @Getter
    @EqualsAndHashCode(callSuper = true)
    @Accessors(fluent = true, chain = true)
    @SuperBuilder
    @JsonDeserialize(builder = SubA.SubABuilder.class) // class not found?
    @JsonTypeName("SubA")
    public class SubA extends AbstractA

    @JsonProperty
    private final String fieldA;



    Thanks










    share|improve this question























      up vote
      8
      down vote

      favorite
      3









      up vote
      8
      down vote

      favorite
      3






      3





      can someone please provide me a working example with the lombok @SuperBuilder experimental annotation?



      I can't get it running and there is no code example as documentation available.



      Currently my code looks like this:



      Superclass:



      @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
      @JsonSubTypes(
      @JsonSubTypes.Type(value = SubA.class),
      @JsonSubTypes.Type(value = AnotherSub.class)
      )
      @Getter
      @Accessors(fluent = true, chain = true)
      @SuperBuilder
      public abstract class AbstractA

      @JsonProperty
      protected final String superProperty;



      And the subclass:



      @Getter
      @EqualsAndHashCode(callSuper = true)
      @Accessors(fluent = true, chain = true)
      @SuperBuilder
      @JsonDeserialize(builder = SubA.SubABuilder.class) // class not found?
      @JsonTypeName("SubA")
      public class SubA extends AbstractA

      @JsonProperty
      private final String fieldA;



      Thanks










      share|improve this question













      can someone please provide me a working example with the lombok @SuperBuilder experimental annotation?



      I can't get it running and there is no code example as documentation available.



      Currently my code looks like this:



      Superclass:



      @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
      @JsonSubTypes(
      @JsonSubTypes.Type(value = SubA.class),
      @JsonSubTypes.Type(value = AnotherSub.class)
      )
      @Getter
      @Accessors(fluent = true, chain = true)
      @SuperBuilder
      public abstract class AbstractA

      @JsonProperty
      protected final String superProperty;



      And the subclass:



      @Getter
      @EqualsAndHashCode(callSuper = true)
      @Accessors(fluent = true, chain = true)
      @SuperBuilder
      @JsonDeserialize(builder = SubA.SubABuilder.class) // class not found?
      @JsonTypeName("SubA")
      public class SubA extends AbstractA

      @JsonProperty
      private final String fieldA;



      Thanks







      java lombok






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 10 at 6:45









      Sebastian Thees

      11316




      11316






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          A working solution in Eclipse, note that the Lombok IntelliJ integration is not supporting all features, therefore the code compiles fine in Eclipse and with javac but IntelliJ thinks it's broken but executes the code without an issue.



          public static ObjectMapper createObjectMapper() 

          final ObjectMapper mapper = new ObjectMapper();
          mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()

          @Override
          public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac)
          if (ac.hasAnnotation(JsonPOJOBuilder.class))
          return super.findPOJOBuilderConfig(ac);

          return new JsonPOJOBuilder.Value("build", "");

          );

          return mapper;


          public static void main(final String args) throws Exception
          final ObjectMapper objectMapper = createObjectMapper();

          final String serializedForm = objectMapper.writeValueAsString(SubA.builder().build());
          System.out.println(serializedForm);
          final SubA anA = objectMapper.readValue(serializedForm, SubA.class);
          System.out.println(anA);



          @Getter
          @EqualsAndHashCode(callSuper = true)
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)
          @JsonTypeName("SubA")
          public static class SubA extends AbstractA

          @JsonProperty
          private final String fieldA;



          @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
          @JsonSubTypes(
          @JsonSubTypes.Type(value = SubA.class)
          )
          @Getter
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          public static abstract class AbstractA

          @JsonProperty
          protected final String superProperty;






          share|improve this answer






















          • I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
            – Sebastian Thees
            Oct 10 at 11:53


















          up vote
          5
          down vote













          Updated 2018-11-10: Lombok 1.18.4 released



          For Lombok's @Builder and @SuperBuilder to work with Jackson, you have to add the builder class header manually and place a @JsonPOJOBuilder(withPrefix="") on it. Lombok will then generate only the remainder of the builder class. This is necessary because Jackson's default is that the builder's setter methods have "with" as prefix, but Lombok's builders don't have any prefix (and Lombok is not and will probably never be configurable in this regard).



          When @SuperBuilder was introduced in Lombok 1.18.2, it was not customizable (i.e., you could not manually add the builder class header). As a result, using @SuperBuilder with Jackson was not easily possible.



          This changed with Lombok 1.18.4 (see this pull request): @SuperBuilder is now (at least partially) customizable, and this allows us to add the annotation. Beware that the code generated by @SuperBuilder is quite complex and heavily loaded with generics. To avoid accidentally messing up the code, you should have a look at the delombok output and copy/paste the class header from there. Here, you need add the builder implementation class header and put the annotation on it:



          @JsonPOJOBuilder(withPrefix="")
          static final class SubABuilderImpl extends SubABuilder<SubA, SubABuilderImpl>



          Note that you have to broaden the visibility of SubABuilderImpl to at least package-private.



          The @JsonDeserialize annotation must also refer to the builder implementation class, not the abstract builder:



          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)





          share|improve this answer






















          • So as a result, you say that using the @SuperBuilder is currently not possible?
            – Sebastian Thees
            Oct 10 at 7:58






          • 1




            It is usable, only that it cannot be used for deserialization with Jackson.
            – Jan Rieke
            Oct 10 at 8:11










          • Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
            – Jan Rieke
            Nov 10 at 17:45










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52734182%2flombok-superbuilder-example-with-json-annotations%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          A working solution in Eclipse, note that the Lombok IntelliJ integration is not supporting all features, therefore the code compiles fine in Eclipse and with javac but IntelliJ thinks it's broken but executes the code without an issue.



          public static ObjectMapper createObjectMapper() 

          final ObjectMapper mapper = new ObjectMapper();
          mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()

          @Override
          public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac)
          if (ac.hasAnnotation(JsonPOJOBuilder.class))
          return super.findPOJOBuilderConfig(ac);

          return new JsonPOJOBuilder.Value("build", "");

          );

          return mapper;


          public static void main(final String args) throws Exception
          final ObjectMapper objectMapper = createObjectMapper();

          final String serializedForm = objectMapper.writeValueAsString(SubA.builder().build());
          System.out.println(serializedForm);
          final SubA anA = objectMapper.readValue(serializedForm, SubA.class);
          System.out.println(anA);



          @Getter
          @EqualsAndHashCode(callSuper = true)
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)
          @JsonTypeName("SubA")
          public static class SubA extends AbstractA

          @JsonProperty
          private final String fieldA;



          @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
          @JsonSubTypes(
          @JsonSubTypes.Type(value = SubA.class)
          )
          @Getter
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          public static abstract class AbstractA

          @JsonProperty
          protected final String superProperty;






          share|improve this answer






















          • I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
            – Sebastian Thees
            Oct 10 at 11:53















          up vote
          2
          down vote



          accepted










          A working solution in Eclipse, note that the Lombok IntelliJ integration is not supporting all features, therefore the code compiles fine in Eclipse and with javac but IntelliJ thinks it's broken but executes the code without an issue.



          public static ObjectMapper createObjectMapper() 

          final ObjectMapper mapper = new ObjectMapper();
          mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()

          @Override
          public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac)
          if (ac.hasAnnotation(JsonPOJOBuilder.class))
          return super.findPOJOBuilderConfig(ac);

          return new JsonPOJOBuilder.Value("build", "");

          );

          return mapper;


          public static void main(final String args) throws Exception
          final ObjectMapper objectMapper = createObjectMapper();

          final String serializedForm = objectMapper.writeValueAsString(SubA.builder().build());
          System.out.println(serializedForm);
          final SubA anA = objectMapper.readValue(serializedForm, SubA.class);
          System.out.println(anA);



          @Getter
          @EqualsAndHashCode(callSuper = true)
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)
          @JsonTypeName("SubA")
          public static class SubA extends AbstractA

          @JsonProperty
          private final String fieldA;



          @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
          @JsonSubTypes(
          @JsonSubTypes.Type(value = SubA.class)
          )
          @Getter
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          public static abstract class AbstractA

          @JsonProperty
          protected final String superProperty;






          share|improve this answer






















          • I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
            – Sebastian Thees
            Oct 10 at 11:53













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          A working solution in Eclipse, note that the Lombok IntelliJ integration is not supporting all features, therefore the code compiles fine in Eclipse and with javac but IntelliJ thinks it's broken but executes the code without an issue.



          public static ObjectMapper createObjectMapper() 

          final ObjectMapper mapper = new ObjectMapper();
          mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()

          @Override
          public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac)
          if (ac.hasAnnotation(JsonPOJOBuilder.class))
          return super.findPOJOBuilderConfig(ac);

          return new JsonPOJOBuilder.Value("build", "");

          );

          return mapper;


          public static void main(final String args) throws Exception
          final ObjectMapper objectMapper = createObjectMapper();

          final String serializedForm = objectMapper.writeValueAsString(SubA.builder().build());
          System.out.println(serializedForm);
          final SubA anA = objectMapper.readValue(serializedForm, SubA.class);
          System.out.println(anA);



          @Getter
          @EqualsAndHashCode(callSuper = true)
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)
          @JsonTypeName("SubA")
          public static class SubA extends AbstractA

          @JsonProperty
          private final String fieldA;



          @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
          @JsonSubTypes(
          @JsonSubTypes.Type(value = SubA.class)
          )
          @Getter
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          public static abstract class AbstractA

          @JsonProperty
          protected final String superProperty;






          share|improve this answer














          A working solution in Eclipse, note that the Lombok IntelliJ integration is not supporting all features, therefore the code compiles fine in Eclipse and with javac but IntelliJ thinks it's broken but executes the code without an issue.



          public static ObjectMapper createObjectMapper() 

          final ObjectMapper mapper = new ObjectMapper();
          mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()

          @Override
          public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac)
          if (ac.hasAnnotation(JsonPOJOBuilder.class))
          return super.findPOJOBuilderConfig(ac);

          return new JsonPOJOBuilder.Value("build", "");

          );

          return mapper;


          public static void main(final String args) throws Exception
          final ObjectMapper objectMapper = createObjectMapper();

          final String serializedForm = objectMapper.writeValueAsString(SubA.builder().build());
          System.out.println(serializedForm);
          final SubA anA = objectMapper.readValue(serializedForm, SubA.class);
          System.out.println(anA);



          @Getter
          @EqualsAndHashCode(callSuper = true)
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)
          @JsonTypeName("SubA")
          public static class SubA extends AbstractA

          @JsonProperty
          private final String fieldA;



          @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
          @JsonSubTypes(
          @JsonSubTypes.Type(value = SubA.class)
          )
          @Getter
          @Accessors(fluent = true, chain = true)
          @SuperBuilder
          public static abstract class AbstractA

          @JsonProperty
          protected final String superProperty;







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 10 at 11:34

























          answered Oct 10 at 11:29









          Andreas

          3,7952134




          3,7952134











          • I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
            – Sebastian Thees
            Oct 10 at 11:53

















          • I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
            – Sebastian Thees
            Oct 10 at 11:53
















          I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
          – Sebastian Thees
          Oct 10 at 11:53





          I think you are right, the IntelliJ plugin has problems generating the code with the annotation. Interesting solution with the JsonPOJOBuilder. All in all, I'll use a different approach than SuperBuilder now. Thanks alot.
          – Sebastian Thees
          Oct 10 at 11:53













          up vote
          5
          down vote













          Updated 2018-11-10: Lombok 1.18.4 released



          For Lombok's @Builder and @SuperBuilder to work with Jackson, you have to add the builder class header manually and place a @JsonPOJOBuilder(withPrefix="") on it. Lombok will then generate only the remainder of the builder class. This is necessary because Jackson's default is that the builder's setter methods have "with" as prefix, but Lombok's builders don't have any prefix (and Lombok is not and will probably never be configurable in this regard).



          When @SuperBuilder was introduced in Lombok 1.18.2, it was not customizable (i.e., you could not manually add the builder class header). As a result, using @SuperBuilder with Jackson was not easily possible.



          This changed with Lombok 1.18.4 (see this pull request): @SuperBuilder is now (at least partially) customizable, and this allows us to add the annotation. Beware that the code generated by @SuperBuilder is quite complex and heavily loaded with generics. To avoid accidentally messing up the code, you should have a look at the delombok output and copy/paste the class header from there. Here, you need add the builder implementation class header and put the annotation on it:



          @JsonPOJOBuilder(withPrefix="")
          static final class SubABuilderImpl extends SubABuilder<SubA, SubABuilderImpl>



          Note that you have to broaden the visibility of SubABuilderImpl to at least package-private.



          The @JsonDeserialize annotation must also refer to the builder implementation class, not the abstract builder:



          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)





          share|improve this answer






















          • So as a result, you say that using the @SuperBuilder is currently not possible?
            – Sebastian Thees
            Oct 10 at 7:58






          • 1




            It is usable, only that it cannot be used for deserialization with Jackson.
            – Jan Rieke
            Oct 10 at 8:11










          • Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
            – Jan Rieke
            Nov 10 at 17:45














          up vote
          5
          down vote













          Updated 2018-11-10: Lombok 1.18.4 released



          For Lombok's @Builder and @SuperBuilder to work with Jackson, you have to add the builder class header manually and place a @JsonPOJOBuilder(withPrefix="") on it. Lombok will then generate only the remainder of the builder class. This is necessary because Jackson's default is that the builder's setter methods have "with" as prefix, but Lombok's builders don't have any prefix (and Lombok is not and will probably never be configurable in this regard).



          When @SuperBuilder was introduced in Lombok 1.18.2, it was not customizable (i.e., you could not manually add the builder class header). As a result, using @SuperBuilder with Jackson was not easily possible.



          This changed with Lombok 1.18.4 (see this pull request): @SuperBuilder is now (at least partially) customizable, and this allows us to add the annotation. Beware that the code generated by @SuperBuilder is quite complex and heavily loaded with generics. To avoid accidentally messing up the code, you should have a look at the delombok output and copy/paste the class header from there. Here, you need add the builder implementation class header and put the annotation on it:



          @JsonPOJOBuilder(withPrefix="")
          static final class SubABuilderImpl extends SubABuilder<SubA, SubABuilderImpl>



          Note that you have to broaden the visibility of SubABuilderImpl to at least package-private.



          The @JsonDeserialize annotation must also refer to the builder implementation class, not the abstract builder:



          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)





          share|improve this answer






















          • So as a result, you say that using the @SuperBuilder is currently not possible?
            – Sebastian Thees
            Oct 10 at 7:58






          • 1




            It is usable, only that it cannot be used for deserialization with Jackson.
            – Jan Rieke
            Oct 10 at 8:11










          • Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
            – Jan Rieke
            Nov 10 at 17:45












          up vote
          5
          down vote










          up vote
          5
          down vote









          Updated 2018-11-10: Lombok 1.18.4 released



          For Lombok's @Builder and @SuperBuilder to work with Jackson, you have to add the builder class header manually and place a @JsonPOJOBuilder(withPrefix="") on it. Lombok will then generate only the remainder of the builder class. This is necessary because Jackson's default is that the builder's setter methods have "with" as prefix, but Lombok's builders don't have any prefix (and Lombok is not and will probably never be configurable in this regard).



          When @SuperBuilder was introduced in Lombok 1.18.2, it was not customizable (i.e., you could not manually add the builder class header). As a result, using @SuperBuilder with Jackson was not easily possible.



          This changed with Lombok 1.18.4 (see this pull request): @SuperBuilder is now (at least partially) customizable, and this allows us to add the annotation. Beware that the code generated by @SuperBuilder is quite complex and heavily loaded with generics. To avoid accidentally messing up the code, you should have a look at the delombok output and copy/paste the class header from there. Here, you need add the builder implementation class header and put the annotation on it:



          @JsonPOJOBuilder(withPrefix="")
          static final class SubABuilderImpl extends SubABuilder<SubA, SubABuilderImpl>



          Note that you have to broaden the visibility of SubABuilderImpl to at least package-private.



          The @JsonDeserialize annotation must also refer to the builder implementation class, not the abstract builder:



          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)





          share|improve this answer














          Updated 2018-11-10: Lombok 1.18.4 released



          For Lombok's @Builder and @SuperBuilder to work with Jackson, you have to add the builder class header manually and place a @JsonPOJOBuilder(withPrefix="") on it. Lombok will then generate only the remainder of the builder class. This is necessary because Jackson's default is that the builder's setter methods have "with" as prefix, but Lombok's builders don't have any prefix (and Lombok is not and will probably never be configurable in this regard).



          When @SuperBuilder was introduced in Lombok 1.18.2, it was not customizable (i.e., you could not manually add the builder class header). As a result, using @SuperBuilder with Jackson was not easily possible.



          This changed with Lombok 1.18.4 (see this pull request): @SuperBuilder is now (at least partially) customizable, and this allows us to add the annotation. Beware that the code generated by @SuperBuilder is quite complex and heavily loaded with generics. To avoid accidentally messing up the code, you should have a look at the delombok output and copy/paste the class header from there. Here, you need add the builder implementation class header and put the annotation on it:



          @JsonPOJOBuilder(withPrefix="")
          static final class SubABuilderImpl extends SubABuilder<SubA, SubABuilderImpl>



          Note that you have to broaden the visibility of SubABuilderImpl to at least package-private.



          The @JsonDeserialize annotation must also refer to the builder implementation class, not the abstract builder:



          @JsonDeserialize(builder = SubA.SubABuilderImpl.class)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 10:34

























          answered Oct 10 at 7:03









          Jan Rieke

          8701213




          8701213











          • So as a result, you say that using the @SuperBuilder is currently not possible?
            – Sebastian Thees
            Oct 10 at 7:58






          • 1




            It is usable, only that it cannot be used for deserialization with Jackson.
            – Jan Rieke
            Oct 10 at 8:11










          • Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
            – Jan Rieke
            Nov 10 at 17:45
















          • So as a result, you say that using the @SuperBuilder is currently not possible?
            – Sebastian Thees
            Oct 10 at 7:58






          • 1




            It is usable, only that it cannot be used for deserialization with Jackson.
            – Jan Rieke
            Oct 10 at 8:11










          • Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
            – Jan Rieke
            Nov 10 at 17:45















          So as a result, you say that using the @SuperBuilder is currently not possible?
          – Sebastian Thees
          Oct 10 at 7:58




          So as a result, you say that using the @SuperBuilder is currently not possible?
          – Sebastian Thees
          Oct 10 at 7:58




          1




          1




          It is usable, only that it cannot be used for deserialization with Jackson.
          – Jan Rieke
          Oct 10 at 8:11




          It is usable, only that it cannot be used for deserialization with Jackson.
          – Jan Rieke
          Oct 10 at 8:11












          Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
          – Jan Rieke
          Nov 10 at 17:45




          Lombok 1.18.4 has been released, allowing customized @SuperBuilders now. I update my answer with a working solution.
          – Jan Rieke
          Nov 10 at 17:45

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52734182%2flombok-superbuilder-example-with-json-annotations%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus