For me, my beans are parsed from JSON and allow partial updates. So, for example, I can PUT /user/1 {"emailAddress": "
f...@gmail.com"} in order to only update the email_address. So I write my bean to record code like this:
private static UserRecord newRecord(UserBean bean) {
UserRecord record = new UserRecord();
bean.getFirstName().ifPresent(record::setFirstName);
bean.getLastName().ifPresent(record::setLastName);
bean.getEmailAddress().ifPresent(record::setEmailAddress);
bean.getPhoneNumberE164().ifPresent(record::setPhoneNumberE164);
return record;
}
So if a getter uses Optional I suppose I would want it to work like this. Of course other people don't see it as good practice to have a getter return an Optional at all. But for my use case it works well to tell the difference between a specified value and an absent value that has been parsed from JSON.
R.