mapper is not able to create the setter and getter methods

940 views
Skip to first unread message

radha krishna

unread,
Jul 24, 2017, 1:56:18 PM7/24/17
to mapstruct-users
Hi,

i am a new user to mapstruct .i am using the "<org.mapstruct.version>1.1.0.Final</org.mapstruct.version>" and my mapper is not generating any setter and getter methods . I tried different code snippets ,but still no luck ,any pointers to debug furthur

my mapper code:

@Mapper
public interface SimpleSourceDestinationMapper {
SimpleSourceDestinationMapper MAPPER = Mappers.getMapper( SimpleSourceDestinationMapper.class ); 
SimpleDestination sourceToDestination(SimpleSource source);
   SimpleSource destinationToSource(SimpleDestination destination);
}


generated code :

public class SimpleSourceDestinationMapperImpl implements SimpleSourceDestinationMapper {

    @Override
    public SimpleDestination sourceToDestination(SimpleSource source) {
        if ( source == null ) {
            return null;
        }

        SimpleDestination simpleDestination = new SimpleDestination();

        return simpleDestination;
    }


Thanks,
radha. 

Andreas Gudian

unread,
Jul 24, 2017, 2:35:20 PM7/24/17
to mapstruct-users
Hi Radha,

How do SimpleSource and SimpleDestination look like? And does the compiler show any warnings for the mapper?

Andreas


--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

radha krishna

unread,
Jul 24, 2017, 2:51:02 PM7/24/17
to mapstruct-users
Hi ,

please do find the objects i am using and warning i observed is 
"Description Resource Path Location Type
Overriding managed version 3.1 for maven-compiler-plugin pom.xml /mySpringBoot line 56 Maven pom Loading Problem
"
public class SimpleSource {
 
    private String name;
    private String description;
 
    // getters and setters
}


public class SimpleDestination {
 
    private String name;
    private String description;
 
    // getters and setters
}

Andreas Gudian

unread,
Jul 24, 2017, 3:05:46 PM7/24/17
to mapstruct-users
Well, nothing funny there. How exactly do the getters and setters look like? Do you use Lombok or something like that as well?

radha krishna

unread,
Jul 24, 2017, 3:19:46 PM7/24/17
to mapstruct-users
as per the example in the "SimpleSourceDestinationMapperImpl"
should have the below generated setter method ,but the in my case i dont see any setters on the generated code :(
 SimpleDestination simpleDestination = new SimpleDestination();
 
        simpleDestination.setName( source.getName() );
        simpleDestination.setDescription( source.getDescription() );
 
-Radha.

Andreas Gudian

unread,
Jul 24, 2017, 3:25:07 PM7/24/17
to mapstruct-users
Okay, could you wrap up your pom.xml, the source and target classes and the mapper in a zip, a gist.github.com entry or a small demo git repo? Something is wrong somewhere because that is nothing that MapStruct should have trouble with 😉

radha krishna

unread,
Jul 24, 2017, 4:10:39 PM7/24/17
to mapstruct-users
yes ,uploaded my files here .please suggest me any other files need.

<script src="https://gist.github.com/radhakrishnavuyyuru/de42b21cfc27936b9806ffd959bfbdcf.js"></script>

Andreas Gudian

unread,
Jul 24, 2017, 4:19:04 PM7/24/17
to mapstruct-users
So your source and destination types actually don’t have any getter and setters? It looks from the gist that the comment “// getter and setter” wasn’t an abbreviation for the mail, but that’s what you have in the code. 

MapStruct doesn’t generate getters and setters. It doesn’t modify your bean classes. Let your IDE do that or do it manually.
What MapStruct does is generating the mapper code by generating the implementation of the mapper Impl class... but it can only use getters / setters that actually exist and that are properly visible (well, public fields are supported as well, but getters and setters should be used generally).

Hope that helps,
Andreas

radha krishna

unread,
Jul 24, 2017, 4:57:18 PM7/24/17
to mapstruct-users
yeah ,you are right .i misinterpreted the example which is having the set and get methods on the generated class .Now i have added the set and get method it is reflection in generated class .

Thanks you so much for your assistance ...
Reply all
Reply to author
Forward
0 new messages