How to use Lombok Builder + Jackson + Graal? #11977
Replies: 2 comments 1 reply
|
After deep diving in the code I think I identified the issue, so I am using module-scan which means that BeanIntrospectionModule is installed. So what BeanIntrospectionModule does is that it makes Jackson use BeanIntrospection rather than reflection to get the setters / getters / builders and other properties. In the above case the code will flow as follows:
For the properties defined and used by the IntrospectionModule has been discovered by Graal and added in the native image But it doesn't set / enrich the build method in the builder which is a bug. Before giving the builder to BeanIntrospectionModule Jackson tries to find the When jackson finally does a check for the _buildMethod to be present here it doesn't find any and throws exception. |
Solution : Complete @introspected configuration (Recommended)Add the missing static builder method to the introspection configuration. import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.core.annotation.Introspected;
import lombok.Builder;
import lombok.Value;
import lombok.jackson.Jacksonized;
@Value
@Builder
@Jacksonized
@Introspected(
builder = @Introspected.IntrospectionBuilder(
builderClass = GitProperties.GitPropertiesBuilder.class,
buildMethod = "build" // Explicitly specify build method
),
accessKind = {Introspected.AccessKind.METHOD, Introspected.AccessKind.FIELD},
classes = {@Introspected.Classed(type = GitProperties.GitPropertiesBuilder.class)}
)
public class GitProperties {
@JsonProperty("git.branch")
String branchName;
@JsonProperty("git.commit.id.abbrev")
String commitAbbrev;
@JsonProperty("git.commit.id.full")
String commitId;
@JsonProperty("git.commit.message.short")
String commitMessage;
@JsonProperty("git.commit.time")
String commitTime;
@JsonProperty("git.commit.user.email")
String committerEmail;
@JsonProperty("git.commit.user.name")
String commitUser;
@JsonProperty("git.build.user.email")
String buildUserEmail;
@JsonProperty("git.build.user.name")
String buildUser;
@JsonProperty("git.build.time")
String buildTime;
// Explicit builder method for GraalVM
public static GitPropertiesBuilder builder() {
return new GitPropertiesBuilder();
}
} |
Uh oh!
There was an error while loading. Please reload this page.
I am trying to use an immutable type like
But when deserialising the value in graal vm I get the error that the build method is not found.
All reactions