I'm trying to parse my object to XML using jackson-dataformat-xml and, when i set the root namespace and parse the file, all properties of my object in the XML gives a empty namespace xmlns="". On jackson's github docs, is advise to use woodstox instead stax XML implementation to solve this but, the behavior still exists.
This is my pojo:
@JacksonXmlRootElement(namespace = "https://www.google.com.br")
public class Cliente implements Serializable {
// Omitted
}
And my parse code:
Cliente cliente = new Cliente();
cliente.setId(new Long(1));
cliente.setNome("Tiago Cassio".toUpperCase());
cliente.setSobrenome("da Conceicao".toUpperCase());
Endereco endereco = new Endereco();
endereco.setId(new Long(1));
endereco.setLogradouro("blablabla");
endereco.setNumero("999");
endereco.setCep("99999");
endereco.setBairro("blablabla");
cliente.setEndereco(endereco);
ObjectMapper mapper = new XmlMapper();
System.out.println(mapper.writeValueAsString(cliente));
This is the XML generated:
<Cliente xmlns="https://www.google.com.br">
<id xmlns="">1</id>
<nome xmlns="">TIAGO CASSIO</nome>
<sobrenome xmlns="">DA CONCEICAO</sobrenome>
<endereco xmlns="">
<id>1</id>
<logradouro>blablabla</logradouro>
<numero>999</numero>
<cep>99999</cep>
<bairro>blablabla</bairro>
</endereco>
</Cliente>
Any idea where is the problem? My project is under a Spring boot version 1.3.0.M5. Thanks for all.
Cliente
annotated with@JacksonXmlProperty
with thenamespace
attribute set on them? If not, can you try doing that to see if that helps? – Fairlie@JacksonXmlProperty (namespace="https://www.google.com.br")
on the properties. Can you check your change again? – Fairlie@JacksonXmlProperty
is one way to do that, and probably simplest. Unfortunately there is no way to specify something like "use this namespace for all properties of this class" (you could file an RFE for jackson xml module if you want, suggesting something easier) – Eula