New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] @Jacksonized does not copy @JsonUnwrapped to @Builder #2736
Comments
I have been facing the same issue with my use case and I took a look at the JacksonizedHandler. It uses the array defined in HandlerUtils with the following members: JACKSON_COPY_TO_BUILDER_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(new String[] {
"com.fasterxml.jackson.annotation.JsonAutoDetect",
"com.fasterxml.jackson.annotation.JsonFormat",
"com.fasterxml.jackson.annotation.JsonIgnoreProperties",
"com.fasterxml.jackson.annotation.JsonIgnoreType",
"com.fasterxml.jackson.annotation.JsonPropertyOrder",
"com.fasterxml.jackson.annotation.JsonRootName",
"com.fasterxml.jackson.annotation.JsonSubTypes",
"com.fasterxml.jackson.annotation.JsonTypeInfo",
"com.fasterxml.jackson.annotation.JsonTypeName",
"com.fasterxml.jackson.annotation.JsonView",
"com.fasterxml.jackson.databind.annotation.JsonNaming",
})); Wouldn't the fix be as simple as adding |
Probably not, because that list is for the builder class, not the setter methods. However, there's another list for that: |
I just realized the sample above is a bit different from our case. Our case is something like this: @Builder
@Jacksonized
public class Foo {
@JsonUnwrapped
private Bar bar;
} If I manually add a builder and annotate the Bar-method as JsonUnwrapped it works as expected. @Builder
@JsonDeserialize(builder = Foo.FooBuilder.class)
public class Foo {
@JsonUnwrapped
private Bar bar;
@JsonPOJOBuilder(withPrefix = "")
public static class FooBuilder {
private Bar bar;
FooBuilder() {}
@JsonUnwrapped
public FooBuilder bar(Bar bar) {
this.bar = bar;
return this;
}
public Foo build() {
return new Foo(bar);
}
}
} In this case the suggestion above should be valid, right? |
Or is it that you mean to say that the |
Exactly. |
So, should I just make a branch and a PR? |
@snystedt I don't use any of these tools so I have to go by what you've all figured out. I don't know what |
…the 'copy to setters' list.
Describe the bug
The
@Jacksonized
annotation says it "[copies] Jackson-related configuration annotations [...] from the class to the builder class." However, it does not copy the@JsonUnwrapped
annotation, which results in incorrect deserialization behavior for objects that require it.To Reproduce
ExampleFile.java
Reproduction Steps
Expected behavior
The
@JsonUnwrapped
annotation should be copied to the builder method. In the specific example above, this should lead to the JSON value successfully parsing.Version info (please complete the following information):
The text was updated successfully, but these errors were encountered: