Skip to content

Add support to configure adding jackson @JsonPOJOBuilder annotations to generated builders#232

Open
maff wants to merge 2 commits intoRandgalt:masterfrom
maff:feature-jackson-annotations
Open

Add support to configure adding jackson @JsonPOJOBuilder annotations to generated builders#232
maff wants to merge 2 commits intoRandgalt:masterfrom
maff:feature-jackson-annotations

Conversation

@maff
Copy link
Contributor

@maff maff commented Jun 3, 2025

Adds a new option structure to instruct record-builder to add a Jackson @JsonPOJOBuilder annotation to the generated builder. While this implements library-specifics, it does not add Jackson as dependency (only on the test module).

Example usage:

Auto-detect Jackson version (default)

@RecordBuilder.Options(jackson = @RecordBuilder.JacksonConfig(jsonPOJOBuilder = true))

Explicitly add Jackson 2.x annotation (fail if J2 is not available):

@RecordBuilder.Options(
    jackson = @RecordBuilder.JacksonConfig(
        jsonPOJOBuilder = true,
        version = JacksonVersion.JACKSON_2
    )
)

With custom setter prefix:

@RecordBuilder.Options(
    jackson = @RecordBuilder.JacksonConfig(jsonPOJOBuilder = true),
    setterPrefix = "set"
)

Closes #229

@maff
Copy link
Contributor Author

maff commented Jun 13, 2025

@Randgalt any feedback on this approach? I would be great to have this as an option for projects relying on Jackson and still wanting to benefit from RecordBuilder's initialization & defaults logic.

return;
}

final var annotationSpec = AnnotationSpec
Copy link

@semyon-levin-workato semyon-levin-workato Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it's not that simple. Recently, Jackson 3 was released with changed package names. Is it possible to check what annotations are presented on the classpath and add appropriate annotation here?

@maff maff force-pushed the feature-jackson-annotations branch from 83b9c46 to 227ce69 Compare February 19, 2026 20:43
Introduces a dedicated Jackson option structure. JSONPojoBuilder support
can be enabled with a boolean flag.

Detects available jackson version on the classpath and adds the
respective annotations when enabled. Jackson version can be set to AUTO
(adds annotation for every found version) or to JACKSON_2 or JACKSON_3
(only adds annotations for defined version, fails the build when library
is not on the classpath).
@maff maff force-pushed the feature-jackson-annotations branch from 227ce69 to 408c108 Compare February 19, 2026 20:49
@maff
Copy link
Contributor Author

maff commented Feb 19, 2026

@Randgalt @semyon-levin-workato Updated to support both Jackson 2 and 3 by detecting available classes on the classpath, with support to specify a specific version in case both versions are present.

Would be awesome if we could progress with this feature for better out-of-the-box Jackson compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make RecordBuilder Jackson-friendly

3 participants

Comments