简体   繁体   中英

JAXB Marshalling supply name space for root element dynamically

I have to pass the namespace for root element dynamically while marshalling using jaxb (JAXB 2.1.10 - JDK 6). i will be using the genrated xml to call different webservices which is qualified with different namespaces but same input xml. here is my sample jaxb annotated class .....guide me with your valuable inputs.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "taskName",
    "taskType"
})
@XmlRootElement(name = "TaskRequest", namespace = "ABC")
public class TaskRequest {

@XmlElement(name = "TaskName", required = true, namespace = "XYZ")
protected String taskName;
@XmlElement(name = "TaskType", required = true, namespace = "XYZ")
protected String taskType;

public String getTaskName() {
    return taskName;
}

public void setTaskName(String value) {
    this.taskName = value;
}

public String getTaskType() {
    return taskType;
}

public void setTaskType(String value) {
    this.taskType = value;
}

}

namespace "ABC" need to pass dynamically with different value.

您可以将根对象包装在JAXBElement的实例中,以提供备用名称和名称空间信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM