This annotation got introduced in JDK 1.5 for a multi-valued property of Java Bean. i.e. if the property is supposed to contain combination of following, then it will use this annotation.
- Text that can be added to java.lang.String
- Child objects/JAXBElements
- Unknown content that won’t get bound to a JAXB class (along with @XmlAnyElement)
While using this annotation with JDK 1.6, I noticed a strange behavior. Here are the details –
Input xml is having following structure
<message> <MyObj> ….. ….. </MyObj> </message>
When we unmarshall this xml using JAXB bundled with JDK 1.5, it returns MyObj object only. But when I migrated to JDK 1.6, it behaved strange. Instead of returning only one object, it returned three –
1st value – “\n”
2nd value – Myobj
3rd value – “\n”
It resulted in in ClassCastException, because it returned String instead of Object at same location. When I removed end of line character from input message, i.e. the message looked like below, it worked fine.
<message><MyObj> ….. ….. </MyObj></message>
Another way to fix it is to migrate to JDK 1.6.0_24. It seems to be fixed in this minor release.