How to specify Namespace with Jackson XmlMapper()

5.2k views Asked by At

I have a POJO that I need to parse to XML. I'm using Jackson 2.10.

I pass my Object and parse as follows:

    ObjectMapper mapper = new XmlMapper(); 
    mapper.enable(SerializationFeature.INDENT_OUTPUT);        
    byte[] val = mapper.writeValueAsBytes(infoToPost);
    System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(infoToPost));

My output has xmlns:wstxnsl. I would like to have it be xmlns:xsi followed by the xsi:type"".

I believe this is because woodstox is used as default. I need to change it.

What do i need to do to make this happen with Jackson?

Desired Output:

<network_object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="subnetNetworkObjectDTO">

Actual Output

<wstxns1:network_objects xmlns:wstxns1="http://www.w3.org/2001/XMLSchema-instance">
0

There are 0 answers