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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:33:27+00:00 2026-05-25T22:33:27+00:00

I have a class with an @XmlRootElement(name=objectName,namespace=https:blahblah) and some attributes in the class all

  • 0

I have a class with an @XmlRootElement(name="objectName",namespace="https:blahblah") and some attributes in the class all with @XmlElement(namespace="https:blahblah")

But now I have some element without an XmlElement annotation. Why is it also marshalled?

I only want to marshal annotated attributes.

Code looks like this:

            JAXBContext jc = JAXBContext.newInstance(SomeClass.class);
        Marshaller m = jc.createMarshaller();
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = dbf.newDocumentBuilder().newDocument();
        m.marshal(someInstanceOfSomeClass, doc );
  • 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-25T22:33:28+00:00Added an answer on May 25, 2026 at 10:33 pm

    JAXB is configuration by exception, this means that it has default rules for converting Java objects to XML. You only need to supply metadata where you need to override the default rules, this greatly reduces the amount of configuration that must be done.

    • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/TheBasics

    You can specify @XmlAccessorType(XmlAccessType.NONE) so that only the annotated fields/properties are marshalled.

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    public class Root {
    
        @XmlElement
        private String foo;  // Will be marshalled
    
        private String bar;  // Will not be marshalled
    
    }
    

    For More Information

    • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.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
Just curious about how jaxb works, I have a class annotated as follows: @XmlRootElement(name
I have a Java bean ala @XmlRootElement public class Bean { @XmlElementWrapper(name = ints)
I have a class like this: @XmlRootElement(name = PricingGroup) public class PricingGroup { ...
I have a class such as the following: @XmlRootElement(name = a) public class ClassA
Say, I have two classes: @XmlRootElement class A { @XmlElement String propertyOfA; @XmlElement B
I have the following: class A{ @XmlElement String name; //getters and setters } and
If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)
I have class Cab(models.Model): name = models.CharField( max_length=20 ) descr = models.CharField( max_length=2000 )
I have this class defintion: @XmlRootElement public class RssRoot { private String _version; private

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.