How to map Beans with public variables and no getter/setters

747 views
Skip to first unread message

jpbon...@gmail.com

unread,
May 27, 2015, 11:51:10 PM5/27/15
to mapstru...@googlegroups.com
I have used Dozer mapping framework in the past and has worked well, but have seen a few disadvantages with it. For the new implementation we were  exploring better frameworks and in the hunt for better frameworks, found  Mapstruct as the most developer friendly and better performing. I can definitely say Mapstruct is the kind of framework that we have been long looking for.

Kudos to all the developers/contributors of this project.

We have two applications for which we want to leverage this framework, the first one is a new application that is developed from ground up and was able to integrate Mapstruct seamlessly. The second one is a legacy application with some POJO Bean objects that only have public variables and have no getters/setters, this is where we are have hit the stumbling block as Mapstruct expects public getters/setters. 

Does anybody know if there is a way in the framework to map public variables without getters/setters? Also, we cannot change the legacy bean objects that violate Java Beans specification as they are used deep inside a very large legacy application.

Also, Is there a way we can commit the generated Impl classes to SVN ? The eclipse (SVN plugin)  is some how ignoring the generated classes.

Thanks in advance.

Gunnar Morling

unread,
May 28, 2015, 2:18:26 AM5/28/15
to mapstru...@googlegroups.com, jpbon...@gmail.com


On Thursday, May 28, 2015 at 5:51:10 AM UTC+2, j...a@gmail.com wrote:
I have used Dozer mapping framework in the past and has worked well, but have seen a few disadvantages with it. For the new implementation we were  exploring better frameworks and in the hunt for better frameworks, found  Mapstruct as the most developer friendly and better performing. I can definitely say Mapstruct is the kind of framework that we have been long looking for.

Kudos to all the developers/contributors of this project.

Thanks :) 

We have two applications for which we want to leverage this framework, the first one is a new application that is developed from ground up and was able to integrate Mapstruct seamlessly. The second one is a legacy application with some POJO Bean objects that only have public variables and have no getters/setters, this is where we are have hit the stumbling block as Mapstruct expects public getters/setters. 

Does anybody know if there is a way in the framework to map public variables without getters/setters? Also, we cannot change the legacy bean objects that violate Java Beans specification as they are used deep inside a very large legacy application.

It's no possible atm. to access fields directly. I just recently filed an issue for it (https://github.com/mapstruct/mapstruct/issues/557), and we can support that for sure in the future. Maybe you would be interested in helping out with implementing it?

If you have accessor methods which just don't match the JavaBeans conventions, e.g. something like propertyName() for reads and withPropertyName() for writes, you may look into the new naming strategy SPI (https://github.com/mapstruct/mapstruct/issues/365) which allows to customize the accessor method naming style and will be part of the upcoming CR1 release.
 
Also, Is there a way we can commit the generated Impl classes to SVN ? The eclipse (SVN plugin)  is some how ignoring the generated classes.

You can definitely commit the generated classes. I don't know the specifics of the Eclipse SVN plug-in, though. Maybe it helps if you use another directory than target/generated-sources (which I could imagine to be ignored by the plug-in by convention), e.g. <PROJECT_DIR>/gen-src?


Thanks in advance.

Cheers,

--Gunnar 

Andreas Gudian

unread,
May 28, 2015, 1:34:46 PM5/28/15
to Gunnar Morling, mapstru...@googlegroups.com, jpbon...@gmail.com
In my daywork project, we used to commit the generated files as well (MapStruct mappers and JPA static metamodel classes). This is how we did it:

* the source-generation was part of the maven-build, but only in case a special profile was activated
* when someone modifies classes that had an effect on the generated stuff, the command "mvn generate-sources -PmySourceGenerationProfile" had to be executed (we had that in a script file). The sources were generated to src/main/generated and we simply committed those files.
* one thing to note is that you'll always find someone who modifies those generated sources manually (which will be overwritten in the next generation), but more often that that we had the case that we simply forgot to run the source generation at all.

By now, we switched to on-the-fly generation both in Maven and in Eclipse - and it works great. It's a whole new feeling, as you always get your feedback instantly. Especially in combination with the MapStruct Eclipse plugin...
And it didn't make the build noticably slower - neither in Eclipse, nor in Maven.

Hope that helps,
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.

jpbon...@gmail.com

unread,
May 30, 2015, 4:42:55 PM5/30/15
to mapstru...@googlegroups.com, jpbon...@gmail.com
Thanks Gunnar for replying to my post. I can definitely see what I can do about the feature implementation for accessing fields directly. Can you please point me to the Source code and Developer's documentation? 

Coming to the issue of unable to commit the generated sources, I think it is SVN plugin that is ignoring them.

On Wednesday, May 27, 2015 at 11:18:26 PM UTC-7, Gunnar Morling wrote:

jpbon...@gmail.com

unread,
May 30, 2015, 4:47:08 PM5/30/15
to mapstru...@googlegroups.com, jpbon...@gmail.com, gunnar....@googlemail.com
Thanks for your reply. 

We do have on the fly generation of the sources from within Eclipse using Annotation processor and for some reason the SVN plugin is ignoring them. I am suspecting it has something do with settings either for Eclipse or SVN plugin.

Gunnar Morling

unread,
Jun 2, 2015, 12:50:46 PM6/2/15
to mapstru...@googlegroups.com, jpbon...@gmail.com
Am Samstag, 30. Mai 2015 22:42:55 UTC+2 schrieb j...a@gmail.com:
Thanks Gunnar for replying to my post. I can definitely see what I can do about the feature implementation for accessing fields directly. Can you please point me to the Source code and Developer's documentation? 


If you'd like to discuss any specific questions around that feature, just add a comment to https://github.com/mapstruct/mapstruct/issues/557.

Thanks,

--Gunnar

Reply all
Reply to author
Forward
0 new messages