JAXB Marshalling supply name space for root element dynamically

Venkat

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.

bdoughan

You can wrap the root object in an instance of JAXBElement to provide alternate name and namespace information.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to avoid root element annotation while marshalling in JAXB?

From Dev

JAXB Marshalling a variable list of elements with the same name

From Dev

ignore root element in JAXB

From Dev

JAXB add element dynamically

From Dev

JAXB marshalling: change element which should declare a namespace

From Dev

JAXB marshalling: change element which should declare a namespace

From Dev

JAXB - Move dynamically generated namespaces to document root

From Dev

JAXB marshalling, ignore nillable

From Dev

Multiple JaxB Marshalling profiles

From Dev

Jaxb marshalling with custom annotations

From Dev

Marshalling LocalDate using JAXB

From Dev

JAXB marshalling for function with arguments

From Dev

Spring JMSListener and JAXB marshalling

From Dev

Marshalling ObservableList with JAXB

From Dev

Adding xml:space to root element

From Dev

JAXB unmarshal choose root name at runtime

From Dev

Root element without children. JAXB

From Dev

Spring + JAXB - Unmarshal XML with the same element root

From Dev

Jaxb - How to avoid "xsi:" at root element

From Dev

Root element without children. JAXB

From Dev

JAXB add additional static root element

From Dev

JAXB custom exception marshalling error

From Dev

JAXB Marshalling Child Class inheritance

From Dev

JAXB marshalling boolean into a complex type

From Dev

Class Casting during Marshalling of JAXB

From Dev

Class Casting during Marshalling of JAXB

From Dev

JAXB custom exception marshalling error

From Dev

JAXB change the Element "name" of @XMLElements annotation

From Dev

Get the site root host name dynamically in .htaccess