JAXB Exception : nor any of its super class is known to this context

When you are working with the JAXB objects, there are some times you would encounter the exception saying the “nor any of its super class is known to this context”. The reason for this error could be many reasons it depends on the environment you are working. The simple solution for fixing the problem is to add

also read:

@XmlSeeAlso({ClassName.class})

When you are working with the JAXB objects, there are some times you would encounter the exception saying the “nor any of its super class is known to this context”. The reason for this error could be many reasons it depends on the environment you are working. The simple solution for fixing the problem is to add

@XmlSeeAlso({ClassName.class})

element in all the classes generated by the JAXB generator. For example, if you are trying to marshall the java object into the XML file using the following code:

JAXBContext jaxbContext = JAXBContext     .newInstance("com.request");

   Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

   // output pretty printed

   jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

   RequestClass request = new RequestClass();

   jaxbMarshaller.marshal(requestClass, file);

The XML file will be generated base don the RequestClass. All the other files would have to add the @XmlSeeAlso({RequestClass.class}) to avoid this exception. It is only the work around and not the fixed solution for this problem.
element in all the classes generated by the JAXB generator. For example, if you are trying to marshall the java object into the XML file using the following code:

JAXBContext jaxbContext = JAXBContext     .newInstance("com.request");

   Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

   // output pretty printed

   jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

   RequestClass request = new RequestClass();

   jaxbMarshaller.marshal(requestClass, file);

The XML file will be generated base don the RequestClass. All the other files would have to add the @XmlSeeAlso({RequestClass.class}) to avoid this exception. It is only the work around and not the fixed solution for this problem.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*