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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:58:43+00:00 2026-05-19T01:58:43+00:00

Having no luck in generating XML with fixed element values using JAXB 2.1 RI.

  • 0

Having no luck in generating XML with fixed element values using JAXB 2.1 RI.
We’re generating XML bound code using xjc and marshall the results.

It works for attributes using <xs:attribute fixed='something'/> and the JAXB customization property fixedAttributeAsConstantProperty.
For elements we figured that there was no way to do the same. Or is there?

As a workaround, we used <xs:element default='something'/> which is turned into @XmlElement(default='something'). Now my guess is that you can tell the marshaller somehow to interpret the default parameter and generate an element with the corresponding content, like <element>something</element>.

I’ve looked at the standard and RI vendor specific marshaller configuration properties without finding something useful.
There seems to be an xjc plug-in that does something similar[1], but I’d be kinda surprised if there is no standard JAXB way to do so.

Any pointers are much appreciated, thanks.

[1] http://fisheye5.cenqua.com/browse/~raw,r=1.5/jaxb2-commons/www/default-value/index.html

  • 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-19T01:58:43+00:00Added an answer on May 19, 2026 at 1:58 am

    The XML schema specification deals with unmarshalling only, i.e. determining the post validation infoset of the source XML representation.

    JAXB appears to mirror this in its support for defaults, i.e. for reading mostly. For instance, the support for default attributes does not extend to writing defaults, just to reading (or accessing from Java using the getter)

    As I see it, the best bet for a solution is to extend the default value plugin to handle fixed elements as well, by making the field final and removing the setter.

    The code for the plugin is very straightforward, really!

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

Sidebar

Related Questions

Possibly a silly question, but I'm having no luck finding an answer. Using Visual
Trying this answer and not having any luck: I am using the SQLite Database
Not having much luck, I have the following if/else statement in Razor which works
It sounds like Mozilla is having good luck improving JavaScript performance with TraceMonkey .
I'm interfacing with a payment gateway and not having any luck with Net::SSLeay and
I am having the worst luck with this. We bought a template to update
Having a problem getting a TreeView control to display node images. The code below
I am not having much luck detecting when a database query in Codeigniter returns
I'm new to structure map and so far having good luck. However, there's one
I am sure this is a simple question, but I am having no luck

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.