I have a class called Lookup
that has two properties:
public class Lookup {
private String surveyName;
private String GUID;
public Lookup(String name, String guid){
this.surveyName = name;
this.GUID = guid;
}
}
In another class, I have a list of Lookup
that I am trying to serialize and save to file. This is how I'm doing it:
List<Lookup> lookup = new ArrayList<Lookup>();
lookup.add(new Lookup("foo","bar"));
XStream serializer = new XStream();
serializer.alias("Lookups",List.class);
String xml = serializer.toXML(lookup);
The XML I end up with is:
<Lookups>
<Lookup>
<GUID>bar</GUID>
</Lookup>
</Lookups>
As you can see, it only serialized the field GUID
but not the field surveyName
. Why is it ignoring that field?
Silly me, the mistake was completely on my end. The field name
was receiving an empty string, and thus XStream must have been ignoring it.