> For the complete documentation index, see [llms.txt](https://incheol-jung.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://incheol-jung.gitbook.io/docs/study/effective-java/undefined-10/undefined-1.md).

# 아이템 87 커스텀 직렬화 형태를 고려해보라

종종 다음 릴리스에서 제대로 다시 구현하기로 하고, 이번 릴리스에서는 그냥 동작만 하도록 만드는 경우가 있다. 보통은 크게 문제되지 않는 전략이다. 하지만 클래스가 Serializab le을 구현하고 기본 직렬화 형태를 사용한다면 다음 릴리스 때 버리려 한 현재의 구현에 영원히 발이 묶이게 된다. 실제로도 BigInteger 같은 일부 자바 클래스가 이 문제에 시달리고 있다.

### 먼저 고민해보고 괜찮다고 판단될 때만 기본 직렬화 형태를 사용하라

직렬화 형태는 유연성, 성능, 정확성 측면에서 신중히 고민한 후 합당할 때만 사용해야 한다. 객체의 물리적 표현과 논리적 내용이 같다면 기본 직렬화 형태라도 무방하다.

### 직렬화 형태를 사용할 때 다음의 문제를 고려해보자

```java
public final class StringList implements Serializable {
    private int size = 0;
    private Entry head = null;

    private static class Entry implements Serializable {
        String data;
        Entry next;
        Entry previous;
    }
    // ... 생략
}
```

* 논리적으로 이 클래스는 일련의 문자열을 표현한다.
* 물리적으로는 문자열들을 이중 연결 리스트로 연결했다.
* 이 클래스에 기본 직렬화 형태를 사용하면 각 노드의 양방향 연결 정보를 포함해 모든 엔트리를 기록한다.

#### 고려해야 할 문제점

1. 공개 API가 현재의 내부 표현 방식에 영구히 묶인다.
2. 너무 많은 공간을 차지할 수 있다.
3. 시간이 너무 많이 걸릴 수 있다.
4. 스택 오버플로를 일으킬 수 있다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://incheol-jung.gitbook.io/docs/study/effective-java/undefined-10/undefined-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
