I'm moving some code from Java 11 to Java 17 and I'm having an issue using Mapstruct to convert a class to a record (that was previously a class).
Let's say I have this record
public record SomeRecord(String a, String b, String c) {}
And I have this other class using Lombok annotations:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class SomeClass{
private String x;
private String y;
private String z;
}
Later in my mapping I have a function to convert from SomeClass
to SomeRecord
@Mapper(componentModel = "spring")
public interface Mapper {
@Mapping(target = "c", source = "someClass.z", qualifiedByName = "mapperFunction")
SomeRecord toSomeRecord(SomeClass someClass);
@Named("mapperFunction")
static String someTransformation(String s) {
//implementation not relevant
}
}
And I'm getting two compiling errors:
- First it says that "Unknown property 'c' in result type SomeRecord. Did you mean 'null'?"
- Secondly it states that there's no "accessible parameterless constructor for
SomeRecord
".
I did research and found that mapstruct is supporting java records so it's not clear for me why these errors are occurring.
I'm using:
- mapstruct 1.5.2.Final (latest as of publication date)
- lombok 1.18.22
- openjdk 17.0.4
Note: Maybe it is evident that I should also move SomeClass
to a record, but for now please assume this is not possible.
Edit: I'm also using Mapstruct + lombok binding and these errors are happening despite.