-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
JAXB @XmlValue deserializing not working with records #559
Comments
I suspect this is related to general issues with annotation merging, records, to be resolved in One challenge here is that it could also be related to XML module handling. It would be great if the issue could be reproduced with Jackson's own annotations, only because then issue could be moved to Actually, I think I'll move this to XML module repo since it can depend on JAXB/Jakarta-Bind annotations but not vice versa. |
Come to think of it, challenging to test even here wrt Records being JDK 15+ feature. Oh well. |
I have a similar problem when adding the attribute public record TestObject(
@XmlElement String name,
@XmlAttribute int age) {
} But this does not: public record TestObject(
@XmlElement(name = "Name") String name,
@XmlAttribute int age) {
} Stacktrace: Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not set final java.lang.String field org.example.Main$TestObject.name to java.lang.String at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:276) at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:627) at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:615) at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:638) at com.fasterxml.jackson.databind.deser.impl.FieldProperty.set(FieldProperty.java:193) at com.fasterxml.jackson.databind.deser.impl.PropertyValue$Regular.assign(PropertyValue.java:60) at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:211) at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:519) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1405) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185) at com.fasterxml.jackson.dataformat.xml.deser.XmlDeserializationContext.readRootValue(XmlDeserializationContext.java:91) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4730) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3677) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3645) at org.example.Main.main(Main.java:28) Caused by: java.lang.IllegalAccessException: Can not set final java.lang.String field org.example.Main$TestObject.name to java.lang.String at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76) at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80) at java.base/jdk.internal.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:79) at java.base/java.lang.reflect.Field.set(Field.java:799) at com.fasterxml.jackson.databind.deser.impl.FieldProperty.set(FieldProperty.java:190) ... 11 more I'm using java 17 and jackson 2.14.2 |
I would recommend trying this against new |
@cowtowncoder Hey, I tried 2.15.0-rc1. I can confirm that the code posted by @toellrich does indeed work with 2.15.0-rc1. However there seems to still be problems with the With the code in the first post, serialization still works but deserializationfails with error:
|
Ok thank you for checking @micopiira. At least things get bit further. |
@XmlAttribute
and@XmlElement
seem to work fine with records, and@XmlValue
seems to work when serializing but deserializing fails withjava.lang.IllegalAccessException
stacktrace:
I'm using java 17 and jackson 2.14.1
The text was updated successfully, but these errors were encountered: