Incompatibility with Project Lombok

625 views
Skip to first unread message

matthie...@gmail.com

unread,
Oct 20, 2015, 9:42:19 AM10/20/15
to Selma
Hello,

It seems that Selma is not compatible with Project Lombok. (https://projectlombok.org/)

Here is a simple example : https://github.com/msaleta/selmalombok.git

There are 2 unit tests :
ModelViewMapperTest.shouldMapModelToViewWithoutLombok : Mapping between ModelObject and ViewObject that declares its getters / setters.
ModelViewMapperTest.shouldMapModelToViewWithLombok : Mapping between ModelObject and ViewObjectLombok that uses Project Lombok to generate getters / setters.

As you can see, the generated classes contains 2 methods :
ModelViewMapperSelmaGeneratedClass.toViewObject that contains the mapping between ModelObject.id and ViewObject.viewId
ModelViewMapperSelmaGeneratedClass.toViewObjectLombok that does not contain the mapping


Is there any workaround to use these 2 libraries together ?

Best regards.

Séven Le Mesle

unread,
Oct 28, 2015, 4:51:11 AM10/28/15
to Selma, matthie...@gmail.com

Hello,

in fact Selma has no concern about using Lombok or not. The thing is that Lombok generates the setter / getter code in a way Selma can not catch. 
So when the Selma processor runs, it is not able to see getter and setters because they are not generated at this time. 

I see 2 solutions to solve this issue :
  • Add the maven Lombok plugin to pre-process the Lombok decorated classes before compilation
  • Separate Lombok decorated beans in a submodule used as a dependency of the module containing Selma mappers. 
I do not see other clean solution for this issue. Perhaps we should add something about this in the documentation.

Regards,

Séven

matthie...@gmail.com

unread,
Oct 28, 2015, 5:33:27 AM10/28/15
to Selma, matthie...@gmail.com
Hi Séven,

Thank you for your answer, but beyond the use of Lombok, I've found another troublesome thing :
In my example, if you just remove the setter (setViewId) from the ViewObject : Selma generates the mapper without the mapping (ModelObject.id -> ViewObject.viewId)

It means that if the destination class doesn't have any setters (Omission, removal, ...), Selma silently generates a mapper that doesn't map anything.

I think Selma should throw an exception on annotation processing because it's clearly a mapping problem. 
Or maybe, just consider that if the developer want to map a field XXX, Selma calls anyway the method setXXX and if this method doesn't exist, the java compiler will generate a compilation error.

Regards,
Matthieu.

Séven Le Mesle

unread,
Oct 28, 2015, 7:09:33 AM10/28/15
to Selma, matthie...@gmail.com
Hi Matthieu,

This is a bug, the standard behavior of Selma for this is to report a compilation failure explaining there are no setters in destination for the source field 'id' in your case. 
Could you please open an issue for that in github ? 

This behavior is managed by the withIgnoreMissing attribute of the annotations and by default it is NONE so every single field not mappable between source and destination should be reported as an error.

Séven

Séven Le Mesle

unread,
Oct 28, 2015, 7:20:02 AM10/28/15
to Selma, matthie...@gmail.com
Oups sorry I missed something in your @Mapper annotation. 

You have setted ignoreMissingProperties = true, so you explicitly ask Selma to bypass the error reporting and ignore all missing fields.
So this is not a bug but a feature :). 
You just have to remove this attribute and the error will be reported as you need.

Regards,

Séven


Le mardi 20 octobre 2015 15:42:19 UTC+2, matthie...@gmail.com a écrit :

matthie...@gmail.com

unread,
Nov 2, 2015, 3:14:51 AM11/2/15
to Selma
Oh ok, sorry for this error.

I didn't expect this property would be active on fields explicitly declared in mapping.
But it might be a reason why this property is now deprecated.

Thanks for your help.
Matthieu.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages