0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DTO の toString() 実践例

Last updated at Posted at 2026-01-13

Utilクラス

public class DtoStringUtil {

    /**
     * null を空文字に変換する
     */
    public String safe(String value) {
        return value == null ? "" : value;
    }
}

@Override
public String toString() {
  DtoStringUtil dtoStringUtil = new DtoStringUtil()
    return "DetailsDto{" +
            "normalCode='" + dtoStringUtil.safe(normalCode) + '\'' +
            ", normalMessage='" + dtoStringUtil.safe(normalMessage) + '\'' +
            ", warningCode='" + dtoStringUtil.safe(warningCode) + '\'' +
            ", warningMessage='" + dtoStringUtil.safe(warningMessage) + '\'' +
            ", errorCode='" + dtoStringUtil.safe(errorCode) + '\'' +
            ", errorMessage='" + dtoStringUtil.safe(errorMessage) + '\'' +
            '}';
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?