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 6049877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:37:33+00:00 2026-05-23T07:37:33+00:00

I’m having issues unmarshalling XML that has been validated against a schema. I have

  • 0

I’m having issues unmarshalling XML that has been validated against a schema.

I have a large schema provided to me that I have extended. Here’s a snippet of what’s provided:

(Namespace “original”)

<xs:element name="Platform" type="PlatformType" abstract="true" />

<xs:complexType name="PlatformType" abstract="true">
   ...
</xs:complexType>

<xs:element name="SpringPlatform" type="SpringPlatformType" substitutionGroup="Platform" />

<xs:complexType name="SpringPlatformType">
    <xs:complexContent>
        <xs:extension base="PlatformType">
            ...
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

Now I’ve extended SpringPlatformType with some additional functionality:

<xsd:element name="MySpringPlatform" type="MySpringPlatformType"
        substitutionGroup="original:SpringPlatform" />

<xsd:complexType name="MySpringPlatformType">
    <xsd:complexContent>
        <xsd:extension base="original:SpringPlatformType">
            <xsd:sequence>
                ...
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

I am receiving a list of Platforms, like this:

<xs:element name="PlatformList" type="PlatformListType" />

<xs:complexType name="PlatformListType">
    <xs:sequence>
        <xs:element ref="Platform" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

I can correctly unmarshall incoming messages that use the original:SpringPlatform elements, but when I try to unmarshall my derived/extended types (MySpringPlatform), I get null. However, the XML validates against my schemas using XMLSpy 2011 just fine.

Any suggestions? I am using JAXB (Metro) 2.2.4 on Java 6u24, Windows XP SP3.

Thanks,

Brian

  • 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-23T07:37:34+00:00Added an answer on May 23, 2026 at 7:37 am

    When you create a JAXB unmarshaller, you need to pass it the context; that is, the package of the structure you’re unmarshalling. We were using a utility class that made it easy for us to do this: pass it the XML string and a package name, and you get back an Object.

    However, when unmarshalling structures that span across multiple namespaces and packages, you need to provide the package name for every package referenced, otherwise the unmarshaller doesn’t have the right context. I never knew you could pass multiple package names to the JAXB context.

    WRONG:

    // Pass package name for the message only.
    JAXBContext jc = JAXBContext.newInstance("com.mycompany.my.messages");
    Unmarshaller u = jc.createUnmarshaller();
    

    RIGHT:

    // Pass package names for all XML structures present in the message.
    JAXBContext jc = JAXBContext.newInstance("com.mycompany.my.types:com.mycompany.my.messages:com.othercompany.their.types");
    Unmarshaller u = jc.createUnmarshaller();
    

    Maybe this was a stupid mistake, but I figured I would share just in case. Reading a bit on this site provided me with the idea. lexicore above also alluded to this, but I thought he was talking about classpath issues; all of the generated classes were always available to the context, however the context wasn’t being told to look for them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.