There are few issues you might face while using JAXB API in JCAPS (Java CAPS).
1. JAXB import statements throw errors, even though Jars are available in common library path.
Somehow JCAPS does not pick up these jars. Do no waste your time and import these libraries in your project itself.
2. JABXContext.createContext(Class) throws error.
Not sure why JCAPS throws error even though the method is available in jaxb api jar.
In this case, use below solution
// Provide comma separated list of packages
JAXBContext jaxbContext = JAXBContext.newInstance("com.test.messaging:com.package2");
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MessageType message = (MessageType )jaxbUnmarshaller.unmarshal(file);
If you are facing ClassCastException on third line, you might want to use this solution.JAXB Unmarshal Classcast Exception
No comments :
Post a Comment