Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jackson fasterxml add namespaces to root element

If I have the class A.java:

@JacksonXmlRootElement(localName = "A")
public class A {

}

The output that gets produced is:

 <A
    xmlns="">

I want to add a few more namespaces to the output, i.e. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com example.xsd"

How do I configure A.java to contain more custom namespaces like these?

like image 796
Hooli Avatar asked Feb 01 '16 15:02

Hooli


1 Answers

Since xsi:schemaLocation is an attribute, you can add it like that:

public class A implements Serializable {

    @JacksonXmlProperty(isAttribute = true, localName = "xsi:schemaLocation")
    private String schemaLocation = "urn:path:to.your.schema";

It did the job for me.

like image 61
Soapr Avatar answered Nov 20 '22 21:11

Soapr