Mapstruct: map generics

Created on 10 Mar 2021  路  3Comments  路  Source: mapstruct/mapstruct

I am trying to map generics like this:

    public static <T, X> Nullable<X> jsonNullableToNullable(JsonNullable<T> jsonNullable) {
        if (jsonNullable.isPresent()) {
            return Nullable.of(jsonNullable.get());
        }
        return Nullable.undefined();
    }

But how do I tell mapstruct in line return Nullable.of(jsonNullable.get()) to call the appropriate mapper to map from T to X?

I have also opened a stackoverflow question with all the details: https://stackoverflow.com/questions/66452786/mapstruct-wrapper-type-and-generics

Most helpful comment

@filiphr Can I give it a try to fix this? I would like to know the exact workflow. For example, some similar unit test we have on this scenario etc. Thanks

All 3 comments

@filiphr Can I give it a try to fix this? I would like to know the exact workflow. For example, some similar unit test we have on this scenario etc. Thanks

Thanks for the offer @JudeNiroshan. However, I think that this should be resolved by PR #2320.

@sjaakd, I've assigned this to you since you are already in that area.

@JudeNiroshan I was wrong, PR #2320 is not fixing this problem. I actually had a look at it and created a reproducal in https://github.com/filiphr/mapstruct/tree/2377.

Let us know if you have some ideas about a potential fix of this.

Was this page helpful?
0 / 5 - 0 ratings