Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:27:29+00:00 2026-05-26T08:27:29+00:00

I have a JAXB generated class, with a collection with the abstract type COBJECT.

  • 0

I have a JAXB generated class, with a collection with the abstract type COBJECT.

COBJECT has multiple descendants, and these descendants also have abstract descendants too.
A snippet from the class hierarchy is as follows:

COBJECT (abstract)
|
|---CDEFINEDOBJECT
    |
    |--CDOMAINTYPE (abstract)
       |
       |---CCODEPHRASE 

When I add an object of CCODEPHRASE to a collection with type COBJECT , such as

protected List<COBJECT> children;

JAXB attempts to create COBJECT, which is an abstract type, and it fails. I’ve tried to add

@XmlElementRefs({
        @XmlElementRef(type = ARCHETYPEINTERNALREF.class),
        @XmlElementRef(type = CONSTRAINTREF.class),
        @XmlElementRef(type = CDEFINEDOBJECT.class),
        @XmlElementRef(type = ARCHETYPESLOT.class),
        @XmlElementRef(type = CCODEPHRASE.class)        
    })
protected List<COBJECT> children;

before children field, but I got “Type or any of its subclasses are not known ” exception in response.

The XML input contains XSI:TYPE= … attribute. How do I make JAXB handle this inheritance structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:27:30+00:00Added an answer on May 26, 2026 at 8:27 am

    You need to ensure that the JAXBContext is aware of the parent class and all the subtypes. This can be done by passing then all in when the JAXBContext is created.

    JAXBContext.createContext.newInstance(Parent.class, Child1.class, Child2.class);
    

    Or you can leverate an @XmlSeeAlso annotation. This lets you specify all the child classes so that you only need to inlcude the root when creating the JAXBContext:

    @XmlSeeAlso({Child1.class, Child2.class}) {
    public class Parent {
    }
    

    For More Information on JAXB and Inheritance

    • http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html
    • http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html
    • http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class
I have an abstract class that looks as follows. public abstract class Entity<PK extends
I have a problem, I have some JAXB generated java files between which there
I have some jaxb objects (instantiated from code generated from xsd by jaxb) that
I have used JAXB to create a class for the following schema (used in
JAXB generated from XSD base64Binary and hexBinary to byte array. I have xsd element
I have a Maven 2 RESTful application using Jersey/JAXB. I generate the JAXB beans
We have this JAXB annotation: @XmlElement(name = Strategy, required = true) protected List<Strategy> strategy;
I have a JAXB setup where I use a @XmlJavaTypeAdapter to replace objects of
I am trying to use the same generated class but in separate packages. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.