Why jackson @JsonAlias Annotation not work with lombok?

Viewed 416

When I received JsonFilter object I expected string to be value of string1 or string2 but the value always null.
So why @JsonAlias not work with lombok?

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JsonFilter {

@JsonAlias({"string1", "string2"})
    private String string;

}

Lombok dependency

 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
        </dependency>
1 Answers

By default, lombok doesn’t copy annotations: you must explicitly instruct it to via onMethod:

@Getter(onMethod=@__({@JsonAlias({"string1", "string2"})}))
private String string;

I notice there’s a lombok config that might offer a global, and therefore better, fix (I haven’t tried it):

lombok.copyableAnnotations = [com.fasterxml.jackson.annotation.JsonAlias]
Related