users@jaxb.java.net

RE: How to get XML name of attributes?

From: Markus Karg <markus.karg_at_gmx.net>
Date: Wed, 11 May 2011 19:56:09 +0200

Wolfgang,

 

thank you for this tip! :-)

 

Regards

Markus

 

From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: Mittwoch, 11. Mai 2011 07:49
To: users_at_jaxb.java.net
Subject: Re: How to get XML name of attributes?

 

On 10 May 2011 15:30, Markus Karg <karg_at_quipsy.de> wrote:

I have some JAXB classes like this one:

 

@XmlElementRoot(name = "foo")

public class Bar {

   @XmlAttribute(name = "xxx")

   public String test;

}

 

With the word "test" in my hands, I need to get "xxx".

 

In other words: How to find out into what attribute name JAXB would marshal
this property?

 

I certainly could use Reflection
(Bar.class.getMethod("test").getAnnotation(XmlAttribute.class)), but this
might get tricky in case that annotation is not given -- my code would have
to repeat the exact rules for JAXB default naming then.


Going from Java to XML isn't so difficult. The JAXB specification defines
this in terms of

   java.beans.Introspector.decapitalize( String name )

applied to class or JavaBean property names.

-W

 

 

So if someone knows some JAXB trick to get this out of the box, I would be
really happy! :-)

 

Thanks

Markus