XStream serializuje wartości null
Przypuśćmy, że mam
class Student
{
String name;
int age;
String teacher;
}
Następnie :
public class App1
{
public static void main(String[] args)
{
Student st = new Student();
st.setName("toto");
XStream xs = new XStream();
xs.alias("student",Student.class);
System.out.println(xs.toXML(st));
}
}
Daje mi :
<student>
<name>toto</name>
<age>0</age>
</student>
Czy istnieje sposób radzenia sobie z wartościami zerowymi? Mam na myśli :
<student>
<name>toto</name>
<age>0</age>
<teacher></teacher>
</student>
Jest to możliwe, jeśli to zrobię
st.setTeacher("");
ale nie, jeśli nauczyciel jest nieważny.
Próbowałem z niestandardowym konwerterem, ale wydaje się, że wartości null nie są wysyłane do konwertera.