FasterXML/jackson-dataformat-xml — Issue #16: newbie questions about customizing XmlMapper
Author: bwalsh
Created: 2012-02-28 20:16:58+00:00
State: open

Greetings. I'm excited about using jackson to serialize xml as well as json. I've got an existing object model that currently uses jackson/json. I have a requirement to produce/consume xml from services that can't handle json.

A few newbie questions around tweaking the output.
I've looked at com.fasterxml.jackson.databind.SerializationConfig etc. but have been unable to unlock the tricks

testFooToXML() Produces
11.11330459205157s
How to suppress nulls ?
How to render date as iso 8601?

testArrayFooToXML() Produces
11.11330459775907s
Foo[] is illegal xml name?

public class TestSerialization {

@Test
public void testFooToXML() throws Exception {
ObjectMapper xmlMapper = new XmlMapper();
Foo f = new Foo();
String xml = xmlMapper.writeValueAsString(f);
System.err.println(xml)	;
}
@Test
public void testArrayFooToXML() throws Exception {
ObjectMapper xmlMapper = new XmlMapper();
Foo[] foos = new Foo[]{ new Foo() };
String xml = xmlMapper.writeValueAsString(foos);
System.err.println(xml)	;
}

public class Foo {
int i = 1 ;
float f = 1.1f ;
Date d = new Date() ;
String s = "s" ;
String n = null ;
public Foo() {
super();
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public float getF() {
return f;
}
public void setF(float f) {
this.f = f;
}
public Date getD() {
return d;
}
public void setD(Date d) {
this.d = d;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public String getN() {
return n;
}
public void setN(String n) {
this.n = n;
}

}
}