• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us

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

April 3, 2012 //  by Krishna Srinivasan

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:

  • XML Tutorials
  • How to Parse XML file using DOM Parser?
  • How to Parse XML file using SAX Parser?
@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.

Category: JavaTag: JAXB

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.

Previous Post: « Writing an OSGi Web Application
Next Post: Download file from HTTP & HTTPS server using Java »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Initialize an Array in Java

Introduction to Java Server Faces (JSF)

Introduction to Java 6.0 New Features, Part–1

Java 6.0 Features Part – 2 : Pluggable Annotation Processing API

Introduction to Java Server Faces(JSF) HTML Tags

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact