-
Notifications
You must be signed in to change notification settings - Fork 117
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
Unable to deserialize YearMonth
when running as java9 module, added with @JsonDeserialize
annotation
#202
Comments
Which version is this tested with, 2.12.1? First: (de)serializers in most modules are intended to be used through registration, and not annotations: so your usage pattern is bit off-label. I know it is done, but I am not quite sure why. So if possible, I would strongly recommend registering the module and not using annotation-based approach. Having said that, it'd be nice to also make this use case work if possible (there are modules that construct (de)serializers in a way that 0-arg constructor cannot work, but I don't think this particular deserializer is like that). I'll add this on my todo list to see if simple construct accessibility change would be possible; and if not, opening up of package might be (I think JPMS requires |
Thanks for having a look. I encountered this with 2.11.4, but also tested against 2.12.1. The issue is still there as the access to constructor is prohibited. Answering to "I know it is done, but I am not quite sure why.". In most cases the answer is simplicity. One annotation and it's done, but there is more. Consider that this way you could have different deserializers for the same type (even in single class):
I did not dig into the topic, but AFAIK I could reigister only one deserializer per type, so I would need to have the same for both fields and all the classes, which is not always what is really wanted. You can also have a look at other classes in the same package. I have not tested them (but went thorugh the code) and saw private constructors for at least one of them as well, so this might affect serializers and deserializers for other types. |
Makes sense. I mostly warn about this being off-brand usage wrt original design as this issue tends to come up from time to time. |
YearMonth
when running as java9 module, added with @JsonDeserialize
annotation
Ok, so, I made the specific change as well as some related ones. I think part of the issue is actually missing "opens" statements in |
Ok, let me see this week. I'll test with SNAPSHOT |
@walkeros much appreciated, looking forward to hearing the results! |
Consider following field annotated with YearMonth deserializer:
It looks to impossible to deserialize in such a way when running your app as named (java9) module. You will get:
The reason for the exception seems is that YearMonthDeserializer is located in
jackson-datatype-jsr310
module and has private default constructor. There is an attempt to access that constructor byClassUtil.checkAndFixAccess
which is located injackson-databind
module. Sincejackson-datatype-jsr310
does not opens that for reflection the call fails and desrialization is not possible.Possible solutions would be change the access to constructor from private to public or open that class for reflection to
jackson-databind
The text was updated successfully, but these errors were encountered: