For my API I'm parsing an object and creating my object with the lombok builder. One of the variables is an "arrivalTime" of type LocalDateTime that, of course, could be null.
I used to have it like this:
visits.add(visit.builder()
.arrivalTime(legacyVisit.getArrivalTime() == null ? null :
LocalDateTime.parse(legacyVisit.getArrivalTime(), ISO_OFFSET_DATE_TIME))
But I'm looking into a nicer way of doing this, maybe using a vavr option? But I'm running into problems. I understand that I put into "map" the logic if it's not null and into "get" the logic if it's null. But I can't do get(null). If arrivalTime is null, I want to keep it as null.
visits.add(visit.builder()
.arrivalTime(Option.of(legacyVisit.getArrivalTime())
.map(p -> LocalDateTime.parse(p, ISO_OFFSET_DATE_TIME)))
I also tried converting my arrivalTime variable in my object to an Option but I just send the object as a response in my API and it turns it into something like this:
"arrivalTime": {
"empty": true,
"lazy": false,
"singleValued": true,
"async": false,
"defined": false,
"orNull": null
},
which is very ugly. Any ideas?