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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:16:26+00:00 2026-05-21T19:16:26+00:00

I am using JAXB with annotations. I want the creditcard info to be displayed

  • 0

I am using JAXB with annotations. I want the creditcard info to be displayed without the creditcardinfo node being displayed. FYI CreditCardInfo is an object of complex type.

@XmlRootElement
public Class Notification{
private String notifDate;
private CreditCardInfo ccInfo;
}

public Class CreditCardInfo{
private int ccNum;
private String expiryMonth;
}

Desired output

<notification>
<date>04/29/11</date>
<ccNum>3456</ccNum>
<expiry_month>November</expiry_month>
</notification>

Regards,
-Anand

  • 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-21T19:16:26+00:00Added an answer on May 21, 2026 at 7:16 pm

    You could use the @XmlPath extension in EclipseLink JAXB (MOXy) to handle this use case. Note: I’m the MOXy lead.

    Notification

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Notification{
    
        @XmlElement(name="date")
        private String notifDate;
    
        @XmlPath(".")
        private CreditCardInfo ccInfo;
    
    }
    

    CreditCardInfo

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class CreditCardInfo{
    
        private int ccNum;
    
        @XmlElement(name="expiry_month")
        private String expiryMonth;
    
    }
    

    Demo

    import java.io.File;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Notification.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Notification notification = (Notification) unmarshaller.unmarshal(new File("input.xml"));
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(notification, System.out);
        }
    
    }
    

    jaxb.properties

    To use MOXy as your JAXB provider you need to add a file named jaxb.properties in the same package as your model classes with the following entry:

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    Input/Output

    <?xml version="1.0" encoding="UTF-8"?>
    <notification>
       <date>04/29/11</date>
       <ccNum>3456</ccNum>
       <expiry_month>November</expiry_month>
    </notification>
    

    For More Information

    • http://bdoughan.blogspot.com/2010/07/xpath-based-mapping.html
    • http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
    • http://bdoughan.blogspot.com/2011/03/map-to-element-based-on-attribute-value.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a new webservice using JAX-WS and JAXB annotations. When I
Do you always need an ObjectFactory class when using JAXB? Without it I get
I am using JAXB to unmarshal an XML file into an object tree. The
We are using JAXB Annotations on our model objects that we return from our
I'm facing problem with Jackson's ObjectMapper using JAXB annotations. To be concrete, I'm having
I want to Create an XML using JAXB. It should have attributes in it
I want to know how to implement having List of interface Type using EclipseLink
When using JAXB with Java-First, fields/properties of type java.util.Date are marshalled and unmarshalled as
I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application's XML
I am using JAXB 2.0 JDK 6 in order to unmarshall an XML instance

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.