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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:53:20+00:00 2026-06-10T02:53:20+00:00

There is little problem with JAXB. Given: Java 1.5; jaxb -jars from jaxws-2_0. .xsd

  • 0

There is little problem with JAXB.


Given:

  • Java 1.5; jaxb -jars from jaxws-2_0.
  • .xsd scheme and generated JAXB classes.
  • Every simple element in .xsd has default value. And as result class members has annotations like
    “@XmlElement(name = “cl_fname”, required = true, defaultValue = “[______]”)“

Required


Get java object (root element) which fully represent xml and every member initialized by default values.


when I try to marshall xml without explicitly setting values, default values doesn’t make sence… is there any way to marshall xml populated with default values without customization of generated classes?

example of .xsd:

<xs:element name="document">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="d_int"/>
            <xs:element ref="d_double"/>
            <xs:element ref="d_string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="d_int" type="xs:int" default="-1"/>
<xs:element name="d_double" type="xs:double" default="-1.0"/>
<xs:element name="d_string" type="xs:string" default="false"/>

and java class:

public class Document {
    @XmlElement(name = "d_int", defaultValue = "-1")
    protected int dInt;
    @XmlElement(name = "d_double", defaultValue = "-1.0")
    protected double dDouble;
    @XmlElement(name = "d_string", required = true, defaultValue = "Default")
    protected String dString;
...
}
  • 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-10T02:53:21+00:00Added an answer on June 10, 2026 at 2:53 am

    default value that is in annotations works only after unmarshalling.
    unmarshal this

    <document>
       <d_int/>
       <d_double/>
       <d_string/>
    </document>  
    

    and you will get object with default values (-1, -1.0, “Default”)

    If you want set default values to marshalling, you should do this

    public class Document {
        @XmlElement(name = "d_int", defaultValue = "-1")
        protected int dInt = 100;
        @XmlElement(name = "d_double", defaultValue = "-1.0")
        protected double dDouble = -100;
        @XmlElement(name = "d_string", required = true, defaultValue = "Default")
        protected String dString = "def";
    ...
    }    
    

    jaxb generate default values only for unmarshalling

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

Sidebar

Related Questions

JAXB generated from XSD base64Binary and hexBinary to byte array. I have xsd element
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I'm making a little app, and there's a small UIWebView there. The problem is
I've almost got it finished. but there's a little problem in adding comments. I've
I have a little problem in object programming in javascript There is a class
I know this probably seems like a little problem. It just feels like there
Having a little problem with an API that's out there and before I admit
I got a little problem with datamapper, and I'd like to know if there
Hi there, I have a little problem with a where query on a has_many
I have a little problem. I want to do automatic searching, but there is

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.