-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19964 Allow json serialization of Object valued attribute #11369
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
base: main
Are you sure you want to change the base?
Conversation
|
@beikov removing the Object type check on the FormatMapper toString/fromString methods makes it work, but with some noteworthy restrictions: |
I'd say this is fine. What will happen during serialization/deserialization is up to the
That is also expected. JSON obviously only knows "object" and "array" and it is up to the configured
I don't think we can improve anything, nor should we. These "restrictions" are fine IMO and simply a result of the fact that a user chose to statically type |
| public final <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) { | ||
| final Type type = javaType.getJavaType(); | ||
| if ( type == String.class || type == Object.class ) { | ||
| if ( type == String.class ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if ( type == String.class ) { | |
| if ( value instanceof String ) { |
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
d97ffb6 to
259604d
Compare
| // Changed from <String> to <Map> since the fix for HHH-19969; the restriction '|| type == Object.class' inside | ||
| // AbstractFormatMapper.fromString() was removed, so now no cast to String happens, but instead the json is serialized | ||
| // to either Map or List (depending on the json format) | ||
| public static class A extends B<Map<?,?>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this change. Are you saying that the JavaType for this payload reported Object.class? Because that would seem somewhat wrong to me, given that deserialization happens when we know about the concrete entity type and can resolve the type variable. Maybe there is another bug hiding here and the check for type == String.class would be more correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are likely correct; so, in both versions of this test (i.e. the original, and my changed one) inside to/fromString the reported javaType.getJavaType() is Object. However, with value instanceof String indeed it just casts to String, whereas with value == String.class it serializes with jackson, leading in the former case to a ClasscastExceltion at String payload1 = a.getPayload(); and I (wrongly) assumed I needed to adapt the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think we're hitting https://hibernate.atlassian.net/browse/HHH-18572 now. I debugged a bit and see that the generic property receives a type resolution containing the type bound of the type variable, which isn't wrong, but leads to this problem.
I have to think about https://hibernate.atlassian.net/browse/HHH-18572 and play around with a potential fix before we can continue with this PR, because changing this test is IMO wrong.
…e mapping Signed-off-by: Jan Schatteman <jschatte@redhat.com>
259604d to
eeae41a
Compare
|
Waiting for resolution of https://hibernate.atlassian.net/browse/HHH-18572 to move this forward |
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19964