Kiedyś pracowałem przy takich god objectach z XMLa (jeszcze za czasów JDK1.6) i rozumiem ból.
Ogólnie - możesz sobie tworzyć wrappery, które będą te gety/sety ogarniać:
public class UserWrapper {
private final UserDto userDto;
private UserWrapper(final UserDto userDto) {
this.userDto = userDto;
}
public Optional<String> getSequenceFormatPublicationLogin() {
return Optional.ofNullable(userDto)
.map(UserDto::getSequence)
.map(e -> e.get(0))
.map(UserSequence::getFormats)
.map(e -> e.get(0))
.map(UserFormat::getPublications)
.map(e -> e.get(0))
.map(UserPublication::getIdent)
.map(UserIdentitiy::getLogin);
}
public void setPublicationToolsDepartmentLogin(final String login) {
UserPublication userPublication = userDto.getPublication();
if (Objects.isNull(userPublication)) {
userPublication = new UserPublication();
userDto.setPublication(userPublication);
}
UserTools userTools = userPublication.getTools();
if (Objects.isNull(userTools)) {
userTools = new UserTools();
userPublication.setTools(userTools);
}
Department department = userTools.getDepartment();
if (Objects.isNull(department)) {
department = new Department();
userTools.setDepartment(userTools);
}
department.setLogin(login);
}
public static UserWrapper of(final UserDto userDto) {
return new UserWrapper(userDto);
}
}
Dzięki temu ukryjesz te brzydkie wyciąganie danych do oddzielnej warstwy i nie będziesz się musiał martwić, że w obiekcie brakuje jakiegoś pola. Z czasem porobiły się wrappery per pewna grupa use-case'ów (tj. miałeś kilka UC korzystało z jednego wrappera, inne z drugiego - ale się nie mieszały) przez co w końcu dało się żyć.