Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

2-step mapping with generics does not work correctly. #2663

Copy link
Copy link

Description

@Zegveld
Issue body actions

Consider the following situation: (removed getter/setters to keep it short)

class Request {
    Nullable<ChildRequest> child;
}

class ChildRequest {
    String name;
}

class RequestDto {
    JsonNullable<ChildRequestDto> child;
}

class ChildRequestDto {
    String name;
}

with the following mapper:

@Mapper
public interface RequestMapper {

    RequestMapper INSTANCE = Mappers.getMapper( RequestMapper.class );

    Request map(RequestDto dto);

    default <T> Nullable<T> jsonNullableToNullable(JsonNullable<T> jsonNullable) {
        if ( jsonNullable.isPresent() ) {
            return Nullable.of( jsonNullable.get() );
        }
        return Nullable.undefined();
    }

    default JsonNullable<ChildRequest> mapJsonNullableChildren(JsonNullable<ChildRequestDto> dtos) {
        if (dtos.isPresent()) {
            return JsonNullable.of( mapChild( dtos.get() ) );
        } else {
            return JsonNullable.undefined();
        }
    }

    ChildRequest mapChild(ChildRequestDto dto);
}

This will not compile, but throw the following errors:

ERROR Issue2377Mapper.java:19 Nullable<ChildRequest> does not have an accessible constructor.
ERROR Issue2377Mapper.java:19 Can't map property "JsonNullable<ChildRequestDto> child" to "Nullable<ChildRequest> child". Consider to declare/implement a mapping method: "Nullable<ChildRequest> map(JsonNullable<ChildRequestDto> value)".

instead of generating the following code:

        request.setChild( jsonNullableToNullable( mapJsonNullableChildren( dto.getChild() ) ) );

Discovered during analysis of #2377 .

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.