publicissapient-france / selma

Selma Java bean mapping that compiles
http://selma-java.org
Apache License 2.0
213 stars 38 forks source link

Bad use of interceptor ? #184

Open surdsey opened 6 years ago

surdsey commented 6 years ago

Hi Slemesle,

I just tried to use a simple interceptor for post-treatment but I Didn' t make it compile with 1.0 or 1.1-snapshot versions, could you tell me if I made a mistake ?

Mapper:

@Mapper(ignoreMissingProperties = true, withIgnoreNullValue = true, withIoC = IoC.SPRING, withCyclicMapping = true, withCustom = {MoneyToMoneyCustomMapper.class, JsonToJsonCustomMapper.class, CustomCampaignInterceptor.class} ) public interface CampaignLightMapper extends CampaignMapper { @Maps(withIgnoreFields = { "distributionCampaignLinks", "company", "reason", "distributedByUser", "deposit" }) CampaignDto asCampaignDto(Campaign in); }

Interceptor:

@Component public class CustomCampaignInterceptor { public void intercept(final Campaign source, final CampaignDto destination) { // Some code entity to dto }

public void intercept(final CampaignDto source, final Campaign destination) { // Some code dto to entity } }

Thank you for your help.

surdsey commented 6 years ago

I always get the same Exception:

Caused by: java.lang.NullPointerException at fr.xebia.extras.selma.codegen.SourceNodeVars.isOutPrimitive(SourceNodeVars.java:162) at fr.xebia.extras.selma.codegen.MappingBuilder.build(MappingBuilder.java:747) at fr.xebia.extras.selma.codegen.MapperMethodGenerator.buildMappingMethod(MapperMethodGenerator.java:190) at fr.xebia.extras.selma.codegen.MapperMethodGenerator.build(MapperMethodGenerator.java:69) at fr.xebia.extras.selma.codegen.MapperClassGenerator.build(MapperClassGenerator.java:161) at fr.xebia.extras.selma.codegen.MapperProcessor.generateMappingClassses(MapperProcessor.java:88) at fr.xebia.extras.selma.codegen.MapperProcessor.process(MapperProcessor.java:71) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) at com.sun.tools.javac.main.Main.compile(Main.java:523) ... 101 more

slemesle commented 6 years ago

Hi @surdsey ,

I've just had a look on this bug, but I am not able to reproduce this error. This exception tells us that the InOutType is null in the SourceNodeVars but, I really don't see how it is possible. Could you post some more code to reproduce the error in integration tests ?

NicoHvt commented 6 years ago

Hi @slemesle , In fact the problems didn't appear without withIgnoreNullValue set to true, I don't know why. For the code, the project is quite bigger and I don't know to more to provide to help us.