在我的程序中,我需要将对象存储在 XML 中。但我不希望所有属性都序列化为 xml。我该怎么做?
public class Car implements ICar{
//all variables has their own setters and getters
private String manufacturer;
private String plate;
private DateTime dateOfManufacture;
private int mileage;
private int ownerId;
private Owner owner; // will not be serialized to xml
.....
}
//code for serialize to xml
public static String serialize(Object obj)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(baos);
encoder.writeObject(obj);
encoder.close();
return baos.toString();
}