0. Remind

직렬화(Serialization)와 역직렬화(Deserialization)

readObject

1. 직렬화/역직렬화 과정에서의 불변식 손상 문제

public final class Period {
    private final Date start;
    private final Date end;
    
    public Period(Date start, Date end) {
        this.start = new Date(start.getTime()); // 방어적 복사 수행
        this.end = new Date(end.getTime());
        
        if(this.start.compareTo(this.end) > 0) { // 매개변수 검증 수행
            throw new IllegalArgumentException(start + "is after then " + end);
        }
    }
    
    public Date start() {
	      return new Date(start.getTime()); // 방어적 복사 수행
	  }
	  
	  public Date end() {
	      return new Date(end.getTime());
	  }
	  
	  @Override
	  public String toString() {
	      return start + " - " + end;
	  }
	  
	  ...
}

readObject의 특성