Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Hi i am trying to convert my POJO to xml using jackson-dataformat-xml 2.7.3 XmlMapper. I am using jackson annotations in POJO class as given in below code But i am getting some unique Ids getting appended in each tag of my list. How can i remove these unique ids.
// Below is
ElementTag Class
import java.util.List;
import
com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
*Element class
public class ElementTag {
@JacksonXmlProperty(localName = "FL")
@JacksonXmlElementWrapper(useWrapping = false)
private List<ProfessionalLeadDetails> pf;
* @return the pf
public List<ProfessionalLeadDetails> getPf() {
return pf;
* @param pf the pf to set
public void setPf(List<ProfessionalLeadDetails> pf) {
this.pf = pf;
// Below is ProfessionalLeadDetails Class
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
public class ProfessionalLeadDetails implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
@JacksonXmlProperty(isAttribute = true)
private String val;
private String value;
* @return the val
public String getVal() {
return val;
* @param val the val to set
public void setVal(String val) {
this.val = val;
* @return the value
public String getValue() {
return value;
* @param value the value to set
public void setValue(String value) {
this.value = value;
// converting to xml using XmlMapper inside main method
XmlMapper xmlMapper = new XmlMapper();
ElementTag et = new ElementTag();
List<ProfessionalLeadDetails> pfList = new
ArrayList<ProfessionalLeadDetails>();
ProfessionalLeadDetails pf = new ProfessionalLeadDetails();
pf.setVal("First Name");
pf.setValue("Sandeep");
pfList.add(pf);
pf = new ProfessionalLeadDetails();
pf.setVal("Email");
pf.setValue("Sandeep@gmail.com");
pfList.add(pf);
pfList.add(pf2);
et.setPf(pfList);
try {
System.out.println(xmlMapper.writer()
.with(SerializationFeature.WRAP_ROOT_VALUE)
.withRootName("Leads").writeValueAsString(et));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
But i am getting some unique ids appended before val like zdef1999262822: as shown below :
OUTPUT
<Leads xmlns=""><FL zdef2041716767:val="First Name"><value>Sandeep</value></FL><FL zdef1999262822:val="Email"><value>Sandeep@gmail.com</value></FL></Leads>
DESIRED OUTPUT:
<Leads xmlns=""><FL val="First Name"><value>Sandeep</value></FL><FL val="Email"><value>Sandeep@gmail.com</value></FL></Leads>
Thanks in advance!
Make sure to use Woodstox Stax implementation, and not Stax implementation Oracle bundles with JDK. This is usually done by adding Maven dependency to explicitly include woodstox jar. This is explained on XML module
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.