对象以错误的方式序列化

我正在尝试序列化对象。像这样的对象已正确序列化:

public class Sound implements Serializable {

   private static final long serialVersionUID = 1L;

   private byte[] sound;
   private String expiringDate;

   public byte[] getSound() {
       return sound;
   }

   public void setSound(byte[] sound) {
       this.sound = sound;
   }

   public String getExpiringDate() {
       return expiringDate;
   }

   public void setExpiringDate(String expiringDate) {
       this.expiringDate = expiringDate;
   }
}

但是只有字符串类型字段的对象像LinkedHashMap对象一样被序列化。

public class Statement implements Serializable {

private static final long serialVersionUID = 2L;

private String text;
private String expiringDate;

public String getText() {
    return text;
}

public void setText(String text) {
    this.text = text;
}

public String getExpiringDate() {
    return expiringDate;
}

public void setExpiringDate(String expiringDate) {
    this.expiringDate = expiringDate;
}
}

当然,从LinkedHashMap获取必要的对象不是问题。

但是,是否存在立即正确序列化它的方法?

评论