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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:48:56+00:00 2026-06-10T03:48:56+00:00

Reflecting on JAXB annotated objects, is there a way to determine if a class/field/method

  • 0

Reflecting on JAXB annotated objects, is there a way to determine if a class/field/method will result in a xsi:type attributed during marshaling?

Is XmlElement annotation,
annotation.type != javax.xml.bind.annotation.XmlElement.DEFAULT.class
the only case I need to worry about?

I’m writing a Lua unmarshaler where we have dropped much of the usual xml type info and I’m trying to figure-out how to match the incoming Lua to JAXB.

Thanks.

–Update–

Here is simple example that shows the problem:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
@XmlSeeAlso({ Cat.class, Dog.class })
public class Animal {
  @XmlElement()
  public List<Animal> critters;
  @XmlAttribute
  public String type;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
public class Dog extends Animal {
  public Dog() {
    this.type = "German Shepherd";
  }
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
public class Cat extends Animal {
  public Cat() {
    this.type = "Black";
  }
}

When I receive an Animal object can I query critter’s annotation to detect that it should be a Dog or Cat and not an Animal?

  • 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-06-10T03:48:57+00:00Added an answer on June 10, 2026 at 3:48 am

    There are a couple circumstances where a JAXB (JSR-222) implementation will write out an xsi:type attribute.

    1. If the field/property is of type Object (or is annotated with @XmlElement(type=Object.class)) and not mapped with @XmlAnyElement(lax=true) and holds an instance of an Object that the JAXBContext has mappings for.
    2. The default mechanism for representing inheritance will result in an xsi:type attribute to represent subclasses (see: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found i have problems when reflecting on a method with generic type paremeter,
Given an ActionScript Function object, is there any way to determine whether that function
I'm reflecting a C++/CLI method that has the following signature: void foo(long n); This
I'm reflecting a property 'Blah' its Type is ICollection public ICollection<string> Blah { get;
How can reflection be used on satellite assemblies? is there any difference in reflecting
I'm reflecting over a class (in a unit test of said class) to make
Is there a way to get the current version of ASP.NET MVC in code?
When reflecting on an interface type, I only get the members of the specific
I am trying to unpack an array I obtain from reflecting an objects fields.
I have a class reflecting my dbml file which extends DataContext, but for some

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.