-
-
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
Iterable
serialization breaks when adding @JsonFilter
annotation
#2390
Comments
Here is a demo of the problem. There are two "wrapper" implementation one for a Collection and one for an Iterable. If no filter is applied they are treated the same and the JSON is what was expected. If you apply an filter at all Iterable breaks. Original source https://github.com/cmercer/jackson-mixin-iterable |
I think I can speculate on the root cause here... The big problem with Because of this, there is simple heuristic: if no logical properties are found to allow serialization as POJO, then (and only then) are add-on/tag interfaces like:
used to serialize values according to these interfaces. So what is likely happening is that wrapper types expose at least one "getter" method, and as a result they are serialized as POJOs, and not just as Note, however, that same limitation does not apply to As to how the specific problem (of forcing wrapper Iterables to be considered "just Iterables"), I am not sure how that could be tackled without breaking other use cases. |
Iterables are handled as you say above (and correctly) in the normal/no filter applied cases. I am adding links below to make it easy on your time. This is the point where the two different ObjectMapper instances are created. Here is where the filters get applied (only to one of the object mappers) This is the specific test case that fails. The results look like the following |
Ok thank you. I'll need to dig bit deeper then it sounds.... I'll see if I can reproduce this with more info. |
Ahhhh. So filters here are Jackson filter functionality and... ok. Should have read original notes with more thought. Does not necessarily explain everything but gives some hint. |
Odd. I can see |
Ah ha. Found it. So... if (ser == null) {
// If we get this far, there were no properties found, so no regular BeanSerializer
// would be constructed. But, couple of exceptions.
// First: if there are known annotations, just create 'empty bean' serializer
if (beanDesc.hasKnownClassAnnotations()) {
return builder.createDummy();
}
} (method called from And in this case, then, it's just that mix-in applied So that is unfortunate. Question then is how to prevent creation of this "helpful" serializer in least unclean fashion. I don't want to add specific check for |
Thanks again for digging into this, I know it is an extreme edge case. |
@cmercer Now that I understand it correctly I think it's perfectly valid bug, and not necessarily super rare (although obv. given it is only now reported is not completely common either :) ). So thank you again for reporting it. |
Iterable
serialization breaks when adding @JsonFilter
annotation
Version: 2.9.9
If an class is Iterable it will serialize correctly with Jackson. However, if I apply a filter at all (even one that does no filtering at all) the Iterable class is turned into an JSON object and contains no data.
We were attempting to use a filter to filter responses back to the user using Spring. Spring PageImpl as a Sort object which is really an Iterable over Sort.Order. Once we applied the filter it broke the JSON for the Sort object.
I have removed all the Spring-ness from a demo project I will attach to this issue later today that shows the issue.
The text was updated successfully, but these errors were encountered: