I am trying to upgrade XMLBeans version 5.1.0 from version 3.1.0. The XML Document when running on the application can not parse with XmlObject.Factory.parse.
XmlObject xmlObj = XmlObject.Factory.parse(content, opts);
It worked well with version 3.1.0 before. But after upgrading to 5.1.0 xmlbeans, it always returns XmlAnyTypeImpl type. Even, it can parse when calling the Inner Factory class directly:
Example: SORAccountReadResponseDocument xmlObj = SORAccountReadResponseDocument.Factory.parse(content,opts);
Has anyone had the same problem and how to solve it? Thank you very much.
This appears to be a problem with XmlBeans since version 5, because someone thought, it would be smart to change XmlObject.Factory from an internal class to a member variable by the same name (including capital 'F').
Sadly that breaks overriding (at least for the JDK i'm using, Adoptium JDK 17), because the member variable that returns XmlAnyTypeImpl will be used instead of the internal class of your document, which would return MyDocumentImpl.
And that's exactly what happens, if you keep using your xsd jars that were compiled with XmlBeans 3 and try to run them against XmlBeans 5.
No idea how Apache doesn't have tests to notice this, or maybe they don't think people will keep using their old xsd jars. I'm not sure having internal classes and member variables compete for the same name is even properly defined in the Java spec.
What you need to do is recompile all of your xsds with XmlBeans 5 and you should be good to go.