Załóżmy, że mamXStream szeregować wartości null
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 do czynienia wartości null? To znaczy:
<student>
<name>toto</name>
<age>0</age>
<teacher></teacher>
</student>
Jest to możliwe, jeśli robię
st.setTeacher("");
ale jeśli nauczyciel nie jest null.
Próbowałem z niestandardowym konwerterem, ale wydaje się, że wartości null nie są wysyłane do konwertera.