-
-
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
JsonTypeInfo
with a subtype having JsonFormat.Shape.ARRAY
and no fields generates {}
not []
#2077
Comments
This combination is unlikely to be supported due to limitations of JSON so while I will not close this yet, I would strongly suggest that you will try to find a solution where subtypes do not use different shapes. |
Reading the problem description again, this is intriguing actually... so will try to have another look. |
Ah. This is because value being serialized is a "root value" -- yet another reason why I think root values should always be simple wrappers themselves. Looks like class annotations not resolved in that case, because |
So: interesting that deserializer does get annotation correctly, expects array shape, but serializer not. Correct solution would be to make sure class annotations checked, possibly format settings passed during initial construction but applied during contextualization. |
Oh. Except that part of the issue is that there are no properties (like mentioned): so only "dummy" serializer is created. |
JsonTypeInfo
with a subtype having JsonFormat.Shape.ARRAY
and no fields generates {}
not []
When a polymorphic interface has a subtype, and the subtype has
@JsonFormat(shape=JsonFormat.Shape.ARRAY)
annotation and no fields, serializing its instance generates an empty object ({}
). However, parsing the interface tries to parse it as an array and fails.Expected result is that it generates an empty array (
[]
) instead of object so that parsing succeeds.Here is a code to reproduce this issue:
Stacktrace of the failure is this:
This problem reproduces with Jackson 2.8.11 and 2.9.6.
This problem doesn't happen if the subtype has at least one field like this:
A workaround is adding
@JsonValue
method to the subtype as following:The text was updated successfully, but these errors were encountered: