In fact, as Hossein Nasr already explained, Lombok cannot know whether there are subclasses that do not have toBuilder=true.

Lombok could require all direct subclasses of an abstract class to also use toBuilder by adding an abstract toBuilder() method on the abstract class. However, there may be use-cases where subclasses should not have a toBuilder (although I haven't seen any good examples of those). Furthermore, indirect subclasses may still lack the toBuilder feature. Therefore, lombok does not enforce toBuilder on subclasses of abstract classes.

Good news is that you can easily work around it in your case (only direct subclasses) by adding the abstract toBuilder() method to your abstract class Parent manually:

@SuperBuilder(toBuilder = true)
public abstract class Parent {
    public abstract ParentBuilder<?, ?> toBuilder();
}

With this change, your copy method compiles and works as expected.

If you also have indirect subclasses, you have to find other means to ensure they also have @SuperBuilder(toBuilder = true). If those would not have this annotation, you may experience strange behavior (e.g. calling copy() will instantiate a different class).

Disclaimer: I implemented the @SuperBuilder feature.

Answer from Jan Rieke on Stack Overflow
🌐
SuperBuilder
superbuilder.sh
SuperBuilder — Build with AI Agents. Know Exactly What's Happening.
Other tools charge $20/mo and give you less. SuperBuilder gives you browser, image gen, DB viewer, scheduler — for free.
🌐
Medium
medium.com › @m2jr › superbuilders-are-a-startups-x-factor-da582f5c7e8d
Superbuilders are a Startup’s “X-Factor” | by Mike Maples, Jr. | Medium
July 14, 2024 - But what I am describing here is more profound: A superbuilder is someone endowed with not just technical prowess but also insatiable curiosity, unwavering tenacity, and a staunch belief in their capability to surmount any technical hurdle.
🌐
Project Lombok
projectlombok.org › api › lombok › experimental › SuperBuilder
SuperBuilder (Lombok)
The SuperBuilder annotation creates a so-called 'builder' aspect to the class that is annotated with @SuperBuilder, but which works well when extending.
🌐
Lars-sh
lars-sh.github.io › lombok-annotations › apidocs › lombok › experimental › SuperBuilder.html
SuperBuilder (Lombok Annotations 1.18.48-SNAPSHOT API)
The SuperBuilder annotation creates a so-called 'builder' aspect to the class that is annotated with @SuperBuilder, but which works well when extending.
🌐
Google Groups
groups.google.com › g › project-lombok › c › Xrgh6Yy24ag
@SuperBuilder needs to be finalized.
Given Oracle's lack of desire to bring Java up to the features .Net developers are used to, I was creating a base class with the common properties. @Builder failed to do the required access to my "properties". @SuperBuilder does. Currently @SuperBuilder is in the "experimental" phase.
🌐
Code Like A Girl
code.likeagirl.io › java-why-lomboks-superbuilder-is-so-useful-0e6c34e61861
Java — Why Lombok’s @Superbuilder Is So Useful | by Cleopatra Douglas | Code Like A Girl
November 4, 2024 - The @SuperBuilder annotation in Java, provided by the Lombok library, is a powerful tool that simplifies the creation of complex builder patterns, especially in inheritance scenarios.
Find elsewhere
🌐
GitHub
github.com › rupac4530-creator › super-builder-platform
GitHub - rupac4530-creator/super-builder-platform: The open-source AI creation platform. Build AI tools, media pipelines, autonomous agents, creator studios, and full applications from one unified system. · GitHub
SuperBuilder is a next-generation AI development platform that combines AI orchestration, autonomous agents, creative pipelines, code generation, deployment, and self-improving intelligence into a single system.
Starred by 15 users
Forked by 4 users
Languages: TypeScript 69.9% | Python 16.2% | PowerShell 8.4% | JavaScript 2.8% | Shell 1.4% | CSS 1.0%
🌐
Baeldung
baeldung.com › home › java › lombok @builder with inheritance
Lombok @Builder with Inheritance | Baeldung
May 11, 2024 - As we noted earlier, version 1.18 of Lombok introduced the @SuperBuilder annotation.
🌐
Super
super.so › builder
Super Builder – Website building template for Notion
Introducing an updated version of the popular Super Builder! A free drag-and-drop website building template for Notion. Comes with over 60 pre-built components and custom themes.
Top answer
1 of 2
24

Updated 2018-11-10: Lombok 1.18.4 released

Updated 2020-10-18: Lombok 1.18.16 released

Lombok 1.18.16 contains the new @Jacksonized annotation. With it, you can simply write:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes({
  @JsonSubTypes.Type(value = SubA.class),
  @JsonSubTypes.Type(value = AnotherSub.class)
})
@Jacksonized
@SuperBuilder
// more annotations...
public abstract class AbstractA {

    @JsonProperty
    protected final String superProperty;
}

@Jacksonized
@SuperBuilder
@JsonTypeName("SubA")
// more annotations...
public class SubA extends AbstractA {

    @JsonProperty
    private final String fieldA;
}

This will automatically insert all necessary Jackson annotations and do some adjustments to the generated builder. No need to customized anymore.

For earlier Lombok versions between 1.18.4 and 1.18.12, this is the way to go:

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)
2 of 2
5

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;
}
🌐
GitHub
github.com › intel › intel-ai-builder
GitHub - intel/intel-ai-builder: Intel® AI Builder (SuperClaw, SuperBuilder)
Intel® AI Builder (SuperClaw, SuperBuilder). Contribute to intel/intel-ai-builder development by creating an account on GitHub.
🌐
Project Lombok
projectlombok.org › features › SuperBuilder
@SuperBuilder
The @SuperBuilder annotation produces complex builder APIs for your classes. In contrast to @Builder, @SuperBuilder also works with fields from superclasses. However, it only works for types.
🌐
Medium
patrickkarsh.medium.com › are-you-a-superbuilder-a0dd88799da7
Are You a Superbuilder?. Superbuilders: The Engineers Who Change… | by Patrick Karsh | Medium
January 4, 2025 - A superbuilder is more than a skilled engineer. They thrive on solving the toughest problems, learning new technologies quickly, and delivering pragmatic, high-impact solutions. They step in when projects seem impossible, timelines are tight, ...
🌐
YouTube
youtube.com › super
Introducing The Super Builder - YouTube
A drag-and-drop landing page builder for Notion.→ https://super.so/builder→ https://twitter.com/super_Music License:https://s.super.so/music-builder
Published: October 7, 2021
Views: 2K
🌐
Super-builder
super-builder.ai
Super-Builder AI | Revolutionize Construction with AI
Bring Super-Builder AI to your jobsite — an intelligent construction assistant built to understand every detail of your project. Super-Builder AI reads drawings and PDFs, answers questions, and helps everyone on your team work more efficiently and stay aligned · Our app uses our construction ...