0

How do we get field name if we have field as below.

@XmlElement(required = true) 
protected String code;  

If i try to get as:

Field f = clazz.getDeclaredField(field); 
XmlElement xmlElement = f.getAnnotation(XmlElement.class);  
xmlElement.name() // returns as ##default instead of code.
Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
  • Note that using the default name can be harmful. Renaming a field is easy. It can be initiated elsewhere than the annotated field declaration. And it would not be backwards compatible with existing XML representations. – Andy Thomas Jun 27 '17 at 21:51

1 Answers1

0

default just means that the property name from the Java bean is used:

http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlElement.html#name%28%29

There are others posts here that deal with the same problem, none of them seems really to explain how to get the value. Here is one: Getting xml element name from unmarshalled java object with JAXB

Community
  • 1
  • 1
Florian S.
  • 386
  • 1
  • 12