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

The Archive Base Latest Questions

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

I have a problem with my JAXB. I have a method with @XmlAnyAttribute (on

  • 0

I have a problem with my JAXB. I have a method with @XmlAnyAttribute (on my getter) but it doesn’t seem to work with the setter (using JAXB RI if it matters).

Simplified code:

@XmlRootElement( name = "element" )
@XmlAccessorType( value = XmlAccessType.PUBLIC_MEMBER )
public class Element
{
    private Map<QName, String> convertedAttributes = new HashMap<QName, String>();

    private List<Attribute> attributes = new ArrayList<Attribute>();

    @XmlAnyAttribute
    public Map<QName, String> getConvertedAttributes() throws Exception
    {
        if ( attributes != null )
        {
            return new AttributeMapAdapter().marshal( attributes );
        }

        return new HashMap<QName, String>();
    }

    public void setConvertedAttributes( Map<QName, String> convertedAttributes )
    {
        this.convertedAttributes = convertedAttributes;
    }

    @XmlTransient
    public List<Attribute> getAttributes()
    {
        return attributes;
    }

    public void setAttributes( List<Attribute> attributes )
    {
        this.attributes = attributes;
    }
}

This work great for marshalling, and I get the output I want. But when I try to unmarshall it, no values it sent to the setter.

I tried moving the @XmlAnyAttribute annotation to the field, and it works fine (but then I can’t do the adaption in the getter).

It kinda feels like a bug, but I’m not sure. Any ideas? I’m using Java 1.6 on Mac OS X (10.7.2)

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

    This isn’t a bug in the JAXB RI. The problem is in your getConvertedAttributes() method. The following works a bit better:

    public Map<QName, String> getConvertedAttributes() throws Exception
    {
        if(!convertedAttributes.isEmpty()) {
            return convertedAttributes;
        }
        if ( attributes != null ) {
            convertedAttributes = new AttributeMapAdapter().marshal( attributes ); 
        } else {
            convertedAttributes = new HashMap<QName, String>();
        }
        return convertedAttributes;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a problem with Jaxb enumerations that is related to this bug https://jaxb.dev.java.net/issues/show_bug.cgi?id=708
I have a web service (built using jaxb/jaxws) that invokes a stateless EJB to
I'm facing a marshalling/unmarshalling problem involving inheritance and polymorphism using MOXy's JAXB implementation and
I have some problem while trying to use the schemagen tool from JAXB library
I have a problem, I have some JAXB generated java files between which there
I have a problem with development resteay+ejb+json. Using Jboss-5.1.0.GA. I get example from resteasy-jaxrs
I have a library of JAXB/Entity objects I am using to unmarshall a xml

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.