Setting nullValueMappingStrategy on the mapper / mapper config level for categories of mappingsOverride a method in Mapper class or customer mapper or attribute mapping- Spring BootMapstruct mapper in src/test/java not generated by maven buildMapStruct : enrich mapping annotation to define custom mapperusing mapstruct how to map an object to a list of objects with spring component mappersMap custom method mapper to MapstructIgnore field in mapper without related property in mapped objectUse the mapper for the base class to map the child classconstants not working when mapperclass has multiple methods with the return type of the constant

Tikz background color of node multilayer

Did Joe Biden "stop a prosecution" into his son in Ukraine? And did he brag about stopping the prosecution?

Can I return my ability to cast Wish by using the Glyph of Warding spell?

Is right click on tables bad UX

Anonymous reviewer disclosed his identity. Should I thank him by name?

What’s the BrE for “shotgun wedding”?

Is "weekend warrior" derogatory?

Is it unethical to give a gift to my professor who might potentially write me a LOR?

Sci-fi story about aliens with cells based on arsenic or nitrogen, poisoned by oxygen

Why is the time of useful consciousness only seconds at high altitudes, when I can hold my breath much longer at ground level?

As a girl, how can I voice male characters effectively?

Mac no longer boots

What are some ways to season that don't rely on garlic and onions?

Bothered by watching coworkers slacking off

Are there types of animals that can't make the trip to space? (physiologically)

C - Learning Linked Lists, Pointer Manipulation - Store some ints, print and free memory

Advices to added homemade symbols

Was there an autocomplete utility in MS-DOS?

Can an animal produce milk all the time?

Would houseruling two or more instances of resistance to the same element as immunity be overly unbalanced?

Non-electric Laser

Can/should you swim in zero G?

Is there any problem with students seeing faculty naked in university gym?

How does case-insensitive collation work?



Setting nullValueMappingStrategy on the mapper / mapper config level for categories of mappings


Override a method in Mapper class or customer mapper or attribute mapping- Spring BootMapstruct mapper in src/test/java not generated by maven buildMapStruct : enrich mapping annotation to define custom mapperusing mapstruct how to map an object to a list of objects with spring component mappersMap custom method mapper to MapstructIgnore field in mapper without related property in mapped objectUse the mapper for the base class to map the child classconstants not working when mapperclass has multiple methods with the return type of the constant






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0















MapStruct documentation has the following to say about the sensible defaults chosen for NullValueMappingStrategy.RETURN_DEFAULT:




Bean mappings: an 'empty' target bean will be returned, with the
exception of constants and expressions, they will be populated when
present.



Primitives: the default values for primitives will be returned, e.g.
false for boolean or 0 for int.



Iterables / Arrays: an empty iterable will be returned.



Maps: an empty map will be returned.




The problem is, we want to be able specify on the @Mapper level that, e.g., Iterables should have NullValueMappingStrategy.RETURN_DEFAULT but not primitives. The reason for this is that an empty iterable is a sensible default for our use case, but 0 is not a sensible default for int. We'd prefer not to have to, e.g., declare:



 @IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)


for every iterable we are mapping.



Does MapStruct provide a clean way to do this that I am not finding in the documentation?










share|improve this question






























    0















    MapStruct documentation has the following to say about the sensible defaults chosen for NullValueMappingStrategy.RETURN_DEFAULT:




    Bean mappings: an 'empty' target bean will be returned, with the
    exception of constants and expressions, they will be populated when
    present.



    Primitives: the default values for primitives will be returned, e.g.
    false for boolean or 0 for int.



    Iterables / Arrays: an empty iterable will be returned.



    Maps: an empty map will be returned.




    The problem is, we want to be able specify on the @Mapper level that, e.g., Iterables should have NullValueMappingStrategy.RETURN_DEFAULT but not primitives. The reason for this is that an empty iterable is a sensible default for our use case, but 0 is not a sensible default for int. We'd prefer not to have to, e.g., declare:



     @IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)


    for every iterable we are mapping.



    Does MapStruct provide a clean way to do this that I am not finding in the documentation?










    share|improve this question


























      0












      0








      0








      MapStruct documentation has the following to say about the sensible defaults chosen for NullValueMappingStrategy.RETURN_DEFAULT:




      Bean mappings: an 'empty' target bean will be returned, with the
      exception of constants and expressions, they will be populated when
      present.



      Primitives: the default values for primitives will be returned, e.g.
      false for boolean or 0 for int.



      Iterables / Arrays: an empty iterable will be returned.



      Maps: an empty map will be returned.




      The problem is, we want to be able specify on the @Mapper level that, e.g., Iterables should have NullValueMappingStrategy.RETURN_DEFAULT but not primitives. The reason for this is that an empty iterable is a sensible default for our use case, but 0 is not a sensible default for int. We'd prefer not to have to, e.g., declare:



       @IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)


      for every iterable we are mapping.



      Does MapStruct provide a clean way to do this that I am not finding in the documentation?










      share|improve this question














      MapStruct documentation has the following to say about the sensible defaults chosen for NullValueMappingStrategy.RETURN_DEFAULT:




      Bean mappings: an 'empty' target bean will be returned, with the
      exception of constants and expressions, they will be populated when
      present.



      Primitives: the default values for primitives will be returned, e.g.
      false for boolean or 0 for int.



      Iterables / Arrays: an empty iterable will be returned.



      Maps: an empty map will be returned.




      The problem is, we want to be able specify on the @Mapper level that, e.g., Iterables should have NullValueMappingStrategy.RETURN_DEFAULT but not primitives. The reason for this is that an empty iterable is a sensible default for our use case, but 0 is not a sensible default for int. We'd prefer not to have to, e.g., declare:



       @IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)


      for every iterable we are mapping.



      Does MapStruct provide a clean way to do this that I am not finding in the documentation?







      mapstruct






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 21:11









      jengelhartjengelhart

      195 bronze badges




      195 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          I think the above line is actually a copy-paste error in the documentation. To make myself clear: the NullValueMappingStrategy only applies to arguments of mapping methods. Not to bean properties. It is not possible to define a primitive argument as source in a bean mapping method.



          It is however possible to define non-beans as source of a bean mapping method. Like the mapFrom method below:



          package org.mapstruct.ap.test.bugs._xyz;

          import java.util.List;

          import org.mapstruct.Mapper;
          import org.mapstruct.NullValueMappingStrategy;
          import org.mapstruct.factory.Mappers;

          @Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
          public interface XyzMapper

          XyzMapper INSTANCE = Mappers.getMapper(XyzMapper.class);

          Target map(Source source);

          Target mapFrom( Integer myInt, List<Integer> myList);

          class Source

          private int myInt;
          private List<Integer> myList;

          public int getMyInt()
          return myInt;


          public void setMyInt(int myInt)
          this.myInt = myInt;


          public List<Integer> getMyList()
          return myList;


          public void setMyList(List<Integer> myList)
          this.myList = myList;



          class Target

          private int myInt;
          private List<Integer> myList;

          public int getMyInt()
          return myInt;


          public void setMyInt(int myInt)
          this.myInt = myInt;


          public List<Integer> getMyList()
          return myList;


          public void setMyList(List<Integer> myList)
          this.myList = myList;







          When using the NullValueMappingStrategy.RETURN_DEFAULT the mapFrom will return an empty Target just as is specified in the documentation.



          This line should be removed from the documentation in relation to the NullValueMappingStrategy: Primitives: the default values for primitives will be returned, e.g. false for boolean or 0 for int.






          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406901%2fsetting-nullvaluemappingstrategy-on-the-mapper-mapper-config-level-for-categor%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0
















            I think the above line is actually a copy-paste error in the documentation. To make myself clear: the NullValueMappingStrategy only applies to arguments of mapping methods. Not to bean properties. It is not possible to define a primitive argument as source in a bean mapping method.



            It is however possible to define non-beans as source of a bean mapping method. Like the mapFrom method below:



            package org.mapstruct.ap.test.bugs._xyz;

            import java.util.List;

            import org.mapstruct.Mapper;
            import org.mapstruct.NullValueMappingStrategy;
            import org.mapstruct.factory.Mappers;

            @Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
            public interface XyzMapper

            XyzMapper INSTANCE = Mappers.getMapper(XyzMapper.class);

            Target map(Source source);

            Target mapFrom( Integer myInt, List<Integer> myList);

            class Source

            private int myInt;
            private List<Integer> myList;

            public int getMyInt()
            return myInt;


            public void setMyInt(int myInt)
            this.myInt = myInt;


            public List<Integer> getMyList()
            return myList;


            public void setMyList(List<Integer> myList)
            this.myList = myList;



            class Target

            private int myInt;
            private List<Integer> myList;

            public int getMyInt()
            return myInt;


            public void setMyInt(int myInt)
            this.myInt = myInt;


            public List<Integer> getMyList()
            return myList;


            public void setMyList(List<Integer> myList)
            this.myList = myList;







            When using the NullValueMappingStrategy.RETURN_DEFAULT the mapFrom will return an empty Target just as is specified in the documentation.



            This line should be removed from the documentation in relation to the NullValueMappingStrategy: Primitives: the default values for primitives will be returned, e.g. false for boolean or 0 for int.






            share|improve this answer





























              0
















              I think the above line is actually a copy-paste error in the documentation. To make myself clear: the NullValueMappingStrategy only applies to arguments of mapping methods. Not to bean properties. It is not possible to define a primitive argument as source in a bean mapping method.



              It is however possible to define non-beans as source of a bean mapping method. Like the mapFrom method below:



              package org.mapstruct.ap.test.bugs._xyz;

              import java.util.List;

              import org.mapstruct.Mapper;
              import org.mapstruct.NullValueMappingStrategy;
              import org.mapstruct.factory.Mappers;

              @Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
              public interface XyzMapper

              XyzMapper INSTANCE = Mappers.getMapper(XyzMapper.class);

              Target map(Source source);

              Target mapFrom( Integer myInt, List<Integer> myList);

              class Source

              private int myInt;
              private List<Integer> myList;

              public int getMyInt()
              return myInt;


              public void setMyInt(int myInt)
              this.myInt = myInt;


              public List<Integer> getMyList()
              return myList;


              public void setMyList(List<Integer> myList)
              this.myList = myList;



              class Target

              private int myInt;
              private List<Integer> myList;

              public int getMyInt()
              return myInt;


              public void setMyInt(int myInt)
              this.myInt = myInt;


              public List<Integer> getMyList()
              return myList;


              public void setMyList(List<Integer> myList)
              this.myList = myList;







              When using the NullValueMappingStrategy.RETURN_DEFAULT the mapFrom will return an empty Target just as is specified in the documentation.



              This line should be removed from the documentation in relation to the NullValueMappingStrategy: Primitives: the default values for primitives will be returned, e.g. false for boolean or 0 for int.






              share|improve this answer



























                0














                0










                0









                I think the above line is actually a copy-paste error in the documentation. To make myself clear: the NullValueMappingStrategy only applies to arguments of mapping methods. Not to bean properties. It is not possible to define a primitive argument as source in a bean mapping method.



                It is however possible to define non-beans as source of a bean mapping method. Like the mapFrom method below:



                package org.mapstruct.ap.test.bugs._xyz;

                import java.util.List;

                import org.mapstruct.Mapper;
                import org.mapstruct.NullValueMappingStrategy;
                import org.mapstruct.factory.Mappers;

                @Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
                public interface XyzMapper

                XyzMapper INSTANCE = Mappers.getMapper(XyzMapper.class);

                Target map(Source source);

                Target mapFrom( Integer myInt, List<Integer> myList);

                class Source

                private int myInt;
                private List<Integer> myList;

                public int getMyInt()
                return myInt;


                public void setMyInt(int myInt)
                this.myInt = myInt;


                public List<Integer> getMyList()
                return myList;


                public void setMyList(List<Integer> myList)
                this.myList = myList;



                class Target

                private int myInt;
                private List<Integer> myList;

                public int getMyInt()
                return myInt;


                public void setMyInt(int myInt)
                this.myInt = myInt;


                public List<Integer> getMyList()
                return myList;


                public void setMyList(List<Integer> myList)
                this.myList = myList;







                When using the NullValueMappingStrategy.RETURN_DEFAULT the mapFrom will return an empty Target just as is specified in the documentation.



                This line should be removed from the documentation in relation to the NullValueMappingStrategy: Primitives: the default values for primitives will be returned, e.g. false for boolean or 0 for int.






                share|improve this answer













                I think the above line is actually a copy-paste error in the documentation. To make myself clear: the NullValueMappingStrategy only applies to arguments of mapping methods. Not to bean properties. It is not possible to define a primitive argument as source in a bean mapping method.



                It is however possible to define non-beans as source of a bean mapping method. Like the mapFrom method below:



                package org.mapstruct.ap.test.bugs._xyz;

                import java.util.List;

                import org.mapstruct.Mapper;
                import org.mapstruct.NullValueMappingStrategy;
                import org.mapstruct.factory.Mappers;

                @Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
                public interface XyzMapper

                XyzMapper INSTANCE = Mappers.getMapper(XyzMapper.class);

                Target map(Source source);

                Target mapFrom( Integer myInt, List<Integer> myList);

                class Source

                private int myInt;
                private List<Integer> myList;

                public int getMyInt()
                return myInt;


                public void setMyInt(int myInt)
                this.myInt = myInt;


                public List<Integer> getMyList()
                return myList;


                public void setMyList(List<Integer> myList)
                this.myList = myList;



                class Target

                private int myInt;
                private List<Integer> myList;

                public int getMyInt()
                return myInt;


                public void setMyInt(int myInt)
                this.myInt = myInt;


                public List<Integer> getMyList()
                return myList;


                public void setMyList(List<Integer> myList)
                this.myList = myList;







                When using the NullValueMappingStrategy.RETURN_DEFAULT the mapFrom will return an empty Target just as is specified in the documentation.



                This line should be removed from the documentation in relation to the NullValueMappingStrategy: Primitives: the default values for primitives will be returned, e.g. false for boolean or 0 for int.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 5 at 18:20









                SjaakSjaak

                1,0018 silver badges18 bronze badges




                1,0018 silver badges18 bronze badges

































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406901%2fsetting-nullvaluemappingstrategy-on-the-mapper-mapper-config-level-for-categor%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript