publicissapient-france / selma

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

Update destination bean #163

Open artsiom-kotau opened 7 years ago

artsiom-kotau commented 7 years ago

I have a date field in my beans. And when I try to use update method E updateEntityWithDto(D dto, E entity); Selma generates the following code: if (dto.getDateField() != null) { entity.setDateField(new java.util.Date(dto.getDateField().getTime())); } else { entity.setDateField(null); } This update schema is applied only for date type. Is it correct behaviour? If yes, how I can get rid of 'else' statement.

slemesle commented 7 years ago

Hi, yes this mapping sounds good since date is not immutable selma creates a copy of the date object. If dateField is null, the updated entity should also have it null. If you want to ignore null values in such case you can add withIgnoreNullValue to the @Mapper annotation.

This will disable the copy of field with null values.

artsiom-kotau commented 7 years ago

I added withIgnoreNullValue, but code generator adds 'else' condition anyway. My mapper configuration is: @Mapper( withIoC = IoC.SPRING, withIoCServiceName = "productMapper", withIgnoreNullValue = true, withIgnoreMissing = IgnoreMissing.ALL `)

slemesle commented 7 years ago

Can you test your code against the snapshot build ? I added some test for this bug. But I can not reproduce it with latest snapshot.

artsiom-kotau commented 7 years ago

Hello, sorry for the delay. I tested against snapshot version, and it looks like the issue has been fixed. When can I get non-snapshot 1.1 version ?

steph06100 commented 6 years ago

Hi guys, I just wanted to try the new field 'withIgnoreNullValue' but I got a nullPointerException while 'mvn clean install' my project.

Btw, this filed is not documented in the documentation of http://www.selma-java.org/

Here is the stacktrace :

Fatal error compiling
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:836)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
Caused by: org.codehaus.plexus.compiler.CompilerException: java.lang.NullPointerException
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:172)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825)
        ... 23 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at com.sun.tools.javac.main.Main.compile(Main.java:553)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
        ... 25 more
Caused by: java.lang.NullPointerException
        at fr.xebia.extras.selma.codegen.SourceNodeVars.isOutPrimitive(SourceNodeVars.java:161)
        at fr.xebia.extras.selma.codegen.MappingBuilder.build(MappingBuilder.java:730)
        at fr.xebia.extras.selma.codegen.MapperMethodGenerator.buildMappingMethod(MapperMethodGenerator.java:143)
        at fr.xebia.extras.selma.codegen.MapperMethodGenerator.build(MapperMethodGenerator.java:63)
        at fr.xebia.extras.selma.codegen.MapperClassGenerator.build(MapperClassGenerator.java:126)
        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)
        ... 28 more