4
@XmlRootElement(name="Root")

public class DynamicHead {

@XmlElement(name="head")
public Head head;

@XmlElement(name="body")
public DynamicBody body;

public DynamicHead() {}
}

Hi, I have simple question. I just wanna change the name property of @XmlElement from java code dynamically. How can I do this?

I found this code in XmlElement source,

@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlElement {
    /**
     * Name of the XML Schema element.
     * <p> If the value is "##default", then element name is derived from the
     * JavaBean property name. 
     */
    String name() default "##default";

Which means, it works on run-time, so isn't it possible to change that value dynamically?

It doesn't matter whether I do coding in this class file or another class file that I use this class. Please help me guys!! :)

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
jamesBlake
  • 166
  • 1
  • 8
  • does your mapper is configured to accept more than one type of XMLs... – Rupesh Oct 18 '13 at 07:20
  • 1
    You can see how to change annotation value at runtime here: http://stackoverflow.com/a/14276270/1713801, though it is very questionable whether you *should* use such approach. – alterfox Oct 18 '13 at 08:25

0 Answers0