Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    carl-unityworks
    @carl-unityworks
    image.png
    image.png
    image.png
    Not sure if this is best way to show example. These 3 pictures shows when name is changed. But 1st pic is mapper, 2nd generated source which calls method, 3rd shows incorrect name.
    10 replies
    carl-unityworks
    @carl-unityworks
    image.png
    Sagar Sudhakar
    @strum07

    Apologies in advance if this has been asked/addressed before..

    Has anyone experienced errors like the following been thrown when you try to go up a version from 1.3.1 to 1.4.1?

    "error: Mapping is not a repeatable annotation type"

    1 reply
    Ivan Franchin
    @ivangfr

    Hi guys! What is the difference between configuring mapstruct like

    <dependencies>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
        ...
    </dependencies>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                ...
                <configuration>
                ...
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

    VS

    <dependencies>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>${org.mapstruct.version}</version>
            <scope>provided</scope>
        </dependency>
        ...
    </dependencies>

    Thanks in advance!

    2 replies
    Ryo Saeba
    @srodrigues37
    Hi i'm newbbie on mapstruct used, i follow tutorials to add it to a springboot project on eclipse. All is working fine if i use gradlew bootRun. But if i start the projet with Boot Dashboard / java application it didn't work. Someone know why?
    Filip Hrisafov
    @filiphr
    How does your gradle configuration look like? If by Boot Dashboard you mean from IntelliJ, then which IntelliJ are you using?
    Ryo Saeba
    @srodrigues37

    I use eclipse not intellij and i add plugin lombok

    id 'io.freefair.lombok' version '5.2.1'

    and Mapstruct

     implementation "org.mapstruct:mapstruct:1.4.1.Final"
        annotationProcessor "org.mapstruct:mapstruct-processor:1.4.1.Final"

    and for spring integration

    compileJava {
      options.compilerArgs << "-Amapstruct.defaultComponentModel=spring"
    }
    full file
    plugins {
        id 'org.springframework.boot' version '2.3.4.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
        id 'java'
        id 'com.palantir.docker' version '0.25.0'
        id 'io.freefair.lombok' version '5.2.1'
    }
    generateLombokConfig.enabled = false
    
    group = 'com.ryosaeba'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '13'
    
    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }
    
    repositories {
        mavenCentral()
    }
    
    ext {
      set('springCloudVersion', "Hoxton.SR8")
    }
    
    dependencies {
        developmentOnly("org.springframework.boot:spring-boot-devtools")
        implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
          implementation 'org.springframework.cloud:spring-cloud-starter-zipkin'
        implementation 'org.springframework.cloud:spring-cloud-starter-config'
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        implementation 'org.springframework.boot:spring-boot-starter-hateoas'
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    
        // Mapstruct
        implementation "org.mapstruct:mapstruct:1.4.1.Final"
        annotationProcessor "org.mapstruct:mapstruct-processor:1.4.1.Final"
        // Lombok
        //implementation "org.projectlombok:lombok"
        //annotationProcessor "org.projectlombok:lombok"
        //testImplementation "org.projectlombok:lombok"
        //testAnnotationProcessor "org.projectlombok:lombok"
    
        runtimeOnly 'com.h2database:h2'
    
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
            exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
        }
    }
    
    dependencyManagement {
      imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
      }
    }
    
    compileJava {
      options.compilerArgs << "-Amapstruct.defaultComponentModel=spring"
    }
    
    test {
        useJUnitPlatform()
    }
    Filip Hrisafov
    @filiphr
    And do you have buildship plugin installed?
    Ryo Saeba
    @srodrigues37
    No
    Ryo Saeba
    @srodrigues37
    I got it, goes on project properties screen->java compiler->annotation processing and Enable projet specific settings
    Ryo Saeba
    @srodrigues37
    But how can i configure my gradle file to do it automaticaly
    Filip Hrisafov
    @filiphr
    I am not an Eclipse user, but I assume that you would need to run the eclipse task to set it up. I think that the Eclipse Buildship plugin is needed for Eclipse and Gradle support. Have a look at https://www.vogella.com/tutorials/EclipseGradle/article.html
    trevize8
    @trevize8
    Hi all! I've been using MapStruct recently, and recently posted and issue (well that's what I thought, really a misunderstanding from my side mapstruct/mapstruct#2246), and related to the configuration solution, I'm hitting another problem: I have a @BeforeMapping method that is not being used in the implementation
    I was saying: I have a @BeforeMapping method that is not being used in the implementation, as long as I'm using @IterableMapping annotation (@IterableMapping(qualifiedByName = "toDtoLocale")). If I removed that @IterableMapping then the implementation will call the method...
    trevize8
    @trevize8
    Is there anything I have to take into account when using @IterableMapping, to make sure the @BeforeMethod will be used on the implementation, just as it is being used in other scenarios where no @IterableMapping annotation is being used in the mapper?
    trevize8
    @trevize8
    just posted this gist with some more context: https://gist.github.com/trevize8/577c1c3d5ed4f528bd0a65b38ff7f55e
    trevize8
    @trevize8
    Ok I see, it is actually same issue I had. Because I am using qualifiedByName, I must ensure the @BeforeMethodis also named like that... Is there any way I can force the method to be used in all the cases, regardless the usage of qualifiedByname? Otherwise I need to declare same method multiple times..
    Filip Hrisafov
    @filiphr
    Yup that is exactly the reason why it is happening. When you use qualifiedByName then only qualified methods are used
    but I understand your use case
    Maybe we can have some other annotation that would mark your @BeforeMethod as always qulifable
    trevize8
    @trevize8
    that would be really helpful, at least in my use case. Not sure if it could considered sort of an edge case, but I think it makes sense to give some option for "I want the @BeforeMethod to be used always" (provided is also eligible based on the mapper return types, parameters and so on of course..). Thanks for the feeback!
    Naga Sarath Chand
    @sarathchand09

    hello team,
    i see problem with mapstruck-processor(1.4.1.final) and lombok on jdk15, lombok 1.18.16 needs to be updated for sneakythrows problem in jdk 15, and mapstruck has a problem on that version, i get the error: "no property named exist match any of the given parameter(s), the same code i have works with lombok 1.18.12, and jdk 13, cant paste my code

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>13</source>
    <target>13</target>\
    <annotationProcessorPaths>
    <path>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>${mapstruct.version}</version>
    </path>
    <!-- other annotation processors -->
    <path>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.12</version>
    </path>
    </annotationProcessorPaths>
    </configuration>
    </plugin>

    Filip Hrisafov
    @filiphr
    Have you checked the Lombok changelog https://projectlombok.org/changelog?
    1 reply
    BREAKING CHANGE: mapstruct users should now add a dependency to lombok-mapstruct-binding. This solves compiling modules with lombok (and mapstruct).
    tillias
    @tillias
    Hello folks, can you please advise if this is fixed since 1.3.1 Final or it is expected to work so? https://stackoverflow.com/questions/64695709/springboottest-with-mapstruct-requires-impl
    Filip Hrisafov
    @filiphr
    This has nothing to do with MapStruct. I've provided you an answer for the question
    2 replies
    suneetk92
    @suneetk92

    Hello everyone,
    I am trying MapStruct Latest version 1.4.1.Final but getting this error

    error: Ambiguous constructors found for creating java.lang.Boolean. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default.

        @Mappings(
                value = [
                    Mapping(source = "phoneNumber", target = "phone"),
                    Mapping(source = "ok", target = "check", qualifiedByName = ["checkOk"])
                ]
        )
        fun convertToDto(person: Person): PersonDto
    
        @Named("checkOk")
        fun checkOk(ok: String?): Boolean? = ok.isNullOrEmpty()
    suneetk92
    @suneetk92

    And if I mark the method as non-nullable

    @Mappings(
                value = [
                    Mapping(source = "phoneNumber", target = "phone"),
                    Mapping(source = "ok", target = "check", qualifiedByName = ["checkOk"])
                ]
        )
        fun convertToDto(person: Person): PersonDto
    
        @Named("checkOk")
        fun checkOk(ok: String?): Boolean = ok.isNullOrEmpty()

    then it is throwing this error

    error: Can't generate mapping method with primitive return type.

    suneetk92
    @suneetk92

    If I try to use typeConvertion methods like

        @Mapping(source = "phoneNumber", target = "phone")
        fun convertToDto(person: Person): PersonDto
    
        fun mapStringToInstant(date: String?): Instant = Instant.now()

    then it is throwing errors like

    error: Instant does not have an accessible constructor.

    How can I add @Default or NoArgsConstructor in classes provided by Java?

    Filip Hrisafov
    @filiphr
    Adding @Named doesn't help. You need to annotate your checkOk method with @JvmDefault from Kotlin
    Otherwise MapStruct will try to do bean mapping between the methods
    Which Kotlin version are you using?
    suneetk92
    @suneetk92
    I am using kotlin - 1.3.72
    I will try @JvmDefault
    suneetk92
    @suneetk92

    Nope, not working. I added @JvmDefault but it is still throwing the same error

        @Mapping(source = "phoneNumber", target = "phone")
        fun convertToDto(person: Person): PersonDto
    
        @Named("checkOk")
        @JvmDefault
        fun checkOk(ok: String?): Boolean? = ok.isNullOrEmpty()

    error: Ambiguous constructors found for creating java.lang.Boolean. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default.

    suneetk92
    @suneetk92

    ok.. found a fix.
    Instead of interface, I have to use abstract class.

    After changing it to abstract class, it is working as expected

    Filip Hrisafov
    @filiphr
    @JvmDefault does not work in 1.3.72. Look at the issue I linked, they fixed it in 1.4.20
    dinosath
    @dinosath
    hello , i have trouble figuring out why mapstruct create 2 implemenentation functions. i have created a mapping for a nested field of a class and that field mapping is from string to bigdecimal but because i get numberformatexception i use another mapper that maps string to bigdecimal without throwing exception but the outer mapper implementation has 2 implementation for mapping the nested field
    2 replies
    Manis
    @madhwani_manish_twitter
    Hi guys , can anyone please help me with this error . 'The return type IDisputeStage is an abstract class or interface. Provide a non abstract/ non interface result type or a factory method .'
    I am stuck there from last two days and really need to get this solved , please help me if anyone know to to do that . IDisputeStage is a interface of a dto class who's object is needed from an entity class object .
    4 replies
    Cassius Vinicius
    @cviniciusm_gitlab

    Hello,

    If I compile and package the project below by Java 11 then the mapper implementation has the builder method so it's correct.

    But if I do the same routine by java 8 then the builder method is not created so the mapper implementation is wrong.

    Project on GitLab: https://gitlab.com/cviniciusm/mapstructdemo

    Filip Hrisafov
    @filiphr
    @cviniciusm_gitlab this is a bug in Lombok (rzwitserloot/lombok#2616)
    Cassius Vinicius
    @cviniciusm_gitlab
    @filiphr Thanks!
    Roman S.A.
    @eaxdev

    Hello! After update to last version mapstruct 1.4.1.Final and spring boot 2.4.0, which include latest lombok. And I have error. My mapper:

    @Mapping(target = "id", source = "id")
    @Mapping(target = "name", source = "name")
    @Mapping(target = "description", source = "description")
    @Mapping(target = "reportName", source = "reportName")
    public abstract ReportViewConstructorDto toViewDto(ReportViewConstructorView reportViewConstructorView);

    ReportViewConstructorDto have lombok annotations:

    @Value
    @Builder
    public class ReportViewConstructorDto {
    //some fields
    }

    When I try compile, I get error:

    Error:(53,61) java: ReportViewConstructorDto(java.lang.Integer,java.lang.String,java.lang.String,java.lang.String) is not public in ru.mts.bi.rest.dto.widget.ReportViewConstructorDto; cannot be accessed from outside package

    If I open implementation, I'll see:

    ReportViewConstructorDto reportViewConstructorDto = new ReportViewConstructorDto( id, name, description, reportName );
    
    return reportViewConstructorDto;

    Why Mapstruct try to create object via constructor instead builder?

    PS: Of cource, I added new lombok dependency lombok-mapstruct-binding.
    PSS: I saw this issue: rzwitserloot/lombok#2616, But my problem not like this bug
    PSSS: I use Java 8

    2 replies