Johannes Leimer
Johannes Leimer
Is there a way to enable mapstruct to handle java.util.Optionals? I'd love to provide a basic mapper config which is able to unwrap an optional and reuse it in my...
I found a way by adding special getters for fields with optionals: ``` private Optional contact; public Contact getNullableContact() { return contact.orElse(null); } ``` the mapping configuration is now: `@Mapping(source...
@filiphr yes, that sounds reasonable. What do you think of these mappings? When source is `Optional` and target is not: `null` -> `null` `empty` -> `null` `present` -> `object` Both...
There is a more generic workaround to handle `Optional` with the current implementation: ``` @Mapping(source = "child", target = "kid", qualifiedByName = "unwrap") Target map(Source source); @Named("unwrap") default T unwrap(Optional...
> @leimer I would say that Optional should never be null (I think it really is a code smell and you must hate your users if thats the case 😉)....
@franzvezuli I don't think this gonna work. ``` @Mapping(source = "child", target = "kid", qualifiedByName = "unwrap") @Mapping(source = "child.name", target = "nameOfKid", qualifiedByName = "unwrap") Target map(Source source); @Mapping(source...
Just realized: the codes get only rendered once. Feels like the x-init attribute is executed only once. I will update my PR. Please stay tuned ;-)
> You are using a very dated library. One which has not been updated for 9 years. Please consider replacing it with a more popular solution. I tried switching to...