mapstruct-idea icon indicating copy to clipboard operation
mapstruct-idea copied to clipboard

Support for Java 14+ records

Open HawkSK opened this issue 3 years ago • 1 comments

When using a java record as a source, the plugin displays a warning:

Unmapped target property: id

even though the mapstruct framework itself does successfully map the record fields.

Moreover, there is no code completion in the source = "" property of @Mapping.

Source code:

@Mapper
public interface RecordMapper {

    AClass toClass(ARecord r);

    record ARecord(Integer id) {
    }

    class AClass {
        private Integer id;

        public AClass() {}

        public AClass(Integer id) {this.id = id;}

        public Integer getId() {return id;}

        public void setId(Integer id) {this.id = id;}
    }
}

Successfully generated:

public class RecordMapperImpl implements RecordMapper {

    @Override
    public AClass toClass(ARecord r) {
        if ( r == null ) {
            return null;
        }

        AClass aClass = new AClass();

        aClass.setId( r.id() );

        return aClass;
    }
}

JDK: 17 Mapstruct version: 1.4.2.Final IntelliJ Idea version: 2022.1 (Ultimate Edition) MapStruct Support Idea version: 1.3.1

HawkSK avatar May 25 '22 20:05 HawkSK

Is the plugin development abandoned or will this feature be released?

fireRising avatar Oct 21 '22 08:10 fireRising

Is the plugin development abandoned or will this feature be released?

Husan avatar Oct 26 '22 05:10 Husan

Perhaps #109 fixes this

ghost avatar Nov 11 '22 08:11 ghost

@JelleDekker-HeadFWD yes but it's not merged yet. And there is no activity.

fireRising avatar Nov 11 '22 12:11 fireRising

@fireRising and @Husan the plugin is not abandoned, it is only that the maintainers of MapStruct (myself included) are doing this in our free time and we don't always have time for everything. The PR is there and it will be merged and a release will be done soonish

filiphr avatar Nov 12 '22 09:11 filiphr

@filiphr Thanks, looking forward to the release😄

fireRising avatar Nov 12 '22 09:11 fireRising