users@jaxb.java.net

Reflection - XML element name?

From: Ralf Kistner <ralfgm_at_gmail.com>
Date: Wed, 14 Sep 2005 11:35:45 +0200

Hi,

In the reflection library, is there a nice way to get the XML element name of a specific property? I am looking for a function similar to RuntimePropertyInfo.getName(), but one that returns the XML name.

I know about RuntimeClassInfo.getElementName(), but this gives the name bound to a class, not to a property.

The only solution I found so far was to search for the annotations myself:

try {
    Field f = item.getClass().getDeclaredField(e.getName());
    if(f.isAnnotationPresent(XmlElement.class)) {
        ename = f.getAnnotation(XmlElement.class).name();
    }
} catch (NoSuchFieldException e1) { }

but this doesn't always work. Does anyone know about a better way to do this?

Kind regards,
Ralf Kistner