-
-
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
@JsonIdentityReference not working with collections #138
Comments
Quick note: Object ids only work for POJOs, and not for Collections (or anything serialized as JSON Arrays, such as arrays) or Maps. Not sure if this is causing problems, but at least annotation on Set property is unnecessary. This limitation is due to practical problems in trying to figure out how to store identity information for Collections, and not a fundamental limitation. However, there are no concrete plans to support identity of collections at this point. |
Contrary to what you say, it works for me if I return an array. Is this is by accident? @JsonIdentityReference(alwaysAsId = true)
private Obj[] objs; {
"id": 1,
"name": "group",
"objs": [
1,
2
]
} |
Ah, no, sorry, my explanation was bit vague. Elements of Collections and arrays will be handled as expected; it's just that actual Collection and array objects will not be referencable. So above is as expected. |
If the above is an expected result and Collections and arrays should be handled the same way then something is probably wrong with handling Collections. Because with {
"id": 1,
"name": "group",
"objs": [
{
"id": 1,
"name": "name 1",
"objGroup": 1
},
{
"id": 2,
"name": "name 2",
"objGroup": 1
}
]
} |
Ok. Yes, it does sound like there is some difference between serializers there. Thank you for clarifications -- I was missing the actual issue. :) |
Test case for Issue #138 @JsonIdentityReference not working with collections
Ok, from whay I can see this will work for collection if ObjectMapper is configured with |
Handling would differ in two cases in that forcing static type allows earlier retrieval of |
Turns out that this was mostly fixed by patch for #97, so serialization will work with 2.1.4. But there is the additional test for deserialization, and that will fail. I am not quite as sure as to what to do with it -- the issue is that there is no real way to resolve Object Id externally. One possibility is to just do bare-bones "stick Object Id in there and hope for best" (which only works for Property Id inclusion); I think I will see if that could work. |
Since #176 is finally implemented, this issue should be resolved. Although not sure what to do with one still failing unit test. |
Looking at the failing test, it can only be resolved by custom Object Id resolver (or by changing annotations used); so it should be solvable. However, as written, test can't be made to work. So I removed the test; we should have actual tests for custom Object Id resolver elsewhere. |
I've got two simple POJO's and a test resource. The problem is that whole ObjGroup.objs are being serialized instead of just id. Everything works as expected if I change objs type from
Set<Obj>
toObj[]
The text was updated successfully, but these errors were encountered: