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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:28:54+00:00 2026-05-30T15:28:54+00:00

I have a Person class (annotated with @XmlRootElement ) in Java with two properties

  • 0

I have a Person class (annotated with @XmlRootElement) in Java with two properties (name, birthday), which I need to marshal in two different ways, generating two different XML files.

In the first file, the Person object should contain only the name property:

<Person>
    <name>John Doe</name>
</Person>

In the second file, the Person object should contain all properties.

<Person>
    <name>John Doe</name>
    <birthday>1980-01-01</birthday>
</Person>

Is there a way to achieve this with JAXB?

Regards,
Jochen

  • 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-30T15:28:55+00:00Added an answer on May 30, 2026 at 3:28 pm

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

    You can use JAXB annotations to provide one representation, and leverage MOXy’s external binding document to provide alternate representations.

    Use Case 1 – Minor Differences Between Representations

    By default MOXy’s external mapping document is used to override metadata provided by annotations. This allows you to tweak the representation between versions. Below is a link to an answer I gave with a detailed example:

    • https://stackoverflow.com/a/9432435/383861

    Use Case 2 – Major Differences Between Representations

    MOXy’s external mapping document can also be used to override all the annotations. This is useful when the representations are not related. Below is a link to an example where I map the same object model to both the Google and Yahoo weather services:

    • http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html

    For More Information

    • http://blog.bdoughan.com/search/label/jaxb.properties
    • http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Person class with two properties: name and address . I want
I have a class Person and a class Name. Name contains two Strings firstName
I have a Person class, with Name and AreaID properties. public class Person {
Say I have a Person class with Name, Age, Level properties. I know how
I have a person class which has a name and a list of friends
I have a Person class which has a String collection of aliases representing additional
I have a class Person which can have several Homes, each one with one
I have a class that is annotated as the @XmlRootElement with @XmlAccessorType(XmlAccessType.NONE) . The
I have class Person as following : class Person { char* name; int age;
I have a class:Person class Person{ String name; String age; } I want to

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.