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;
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
add a comment
|
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
add a comment
|
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
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
mapstruct
asked Mar 28 at 21:11
jengelhartjengelhart
195 bronze badges
195 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
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.
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment
|
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.
add a comment
|
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.
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.
answered Apr 5 at 18:20
SjaakSjaak
1,0018 silver badges18 bronze badges
1,0018 silver badges18 bronze badges
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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