-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Possibly wrong behavior of @JsonMerge #4783
Comments
Why would you try to confuse type resolution? Below seems enough for reprouction. class MergeListTest {
private static class MyArrayList<T> extends ArrayList<T> {
static int constructorCount = 0;
public MyArrayList() {
if (constructorCount > 0) {
throw new Error("Should only be called once");
}
++constructorCount;
}
}
public static class MergeList {
@JsonMerge
@JsonProperty
List<String> values = create();
}
public static List<String> create() {
List<String> list = new MyArrayList<>();
list.add("a");
return list;
}
public static void main(String[] args) throws Exception {
JsonMapper MAPPER = JsonMapper.builder().build();
MergeList mergeList = new MergeList();
// Fails with exception here
MergeList w = MAPPER.readValue(("{\"values\":[\"x\"]}"), MergeList.class);
}
} |
I don't know honestly. The documentation does not mention anything about instantiation. The part of JavaDoc shared...
... also could be understood as "incoming collection into existing collection", though the expressions may be ambiguous? Additionally, here is blog written about, when @JsonMerge first came out. You may find some more hint on what original intention would be. |
I think this case should work so it seems like a legit bug. There are quite a few Checking in simplified/minimal reproduction under |
Search before asking
Describe the bug
From #4756:
Test case:
Throws
If I understood
@JsonMerge
correctly, it should have resolved correctly:But the error is that Jackson cannot find a deserializer for
MyList
. It doesn't need to because it can access the current value (with a getter or@JsonProperty
as in this example) and modify it. Without@JsonMerge
, the current state of thevalues
field is not considered and so I expect exactly this kind of failure.Perhaps I misunderstood
@JsonMerge
, but the docs are quite clear I think.A workaround is possible via a custom setter:
But this "pollutes" the class and also requires
opens
declarations inmodule-info
to be able to read theprivate
setter.Version Information
2.17 and 2.18
The text was updated successfully, but these errors were encountered: