what would be the configuration for mapStruct to stop mapping a DTO's super class's fields?Why does this MapStruct generated class does not include import statement?JHipster EntityMapper interface (mapstruct): map a Spring projection interfacejava - MapStruct unable to map fields in base class in mapper functionMapStruct map correct instance of object based on target typeMapStruct - Wrong datatype is considered while generating the mapper implementation classMapstruct map one field to multiple target fields and vice versaMapStruct equivalent of hint(Dozer)?Ambiguous mapping methods using java MapstructMapstruct: How to map A extends SingleValue<T> to T and A extends SingleValue<T> to B extends SingleValue<T> with the same mapper?How to use mapstruct on the parent object to detect the right child mapper?
Placing bypass capacitors after VCC reaches the IC
How can I find where certain bash function is defined?
How many chess players are over 2500 Elo?
Mother abusing my finances
Is there a general effective method to solve Smullyan style Knights and Knaves problems? Is the truth table method the most appropriate one?
Why colon to denote that a value belongs to a type?
At what point in European history could a government build a printing press given a basic description?
What is the 中 in ダウンロード中?
How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?
How long does it take to crack RSA 1024 with a PC?
Python program to convert a 24 hour format to 12 hour format
Full backup on database creation
Crossing US border with music files I'm legally allowed to possess
ESTA/WVP - leaving US within 90 days, then staying in DR
Looking for a soft substance that doesn't dissolve underwater
What are these arcade games in Ghostbusters 1984?
How were these pictures of spacecraft wind tunnel testing taken?
Under what law can the U.S. arrest International Criminal Court (ICC) judges over war crimes probe?
Windows 10 Programs start without visual Interface
Where did Wilson state that the US would have to force access to markets with violence?
Is there a down side to setting the sampling time of a SAR ADC as long as possible?
Why do they consider the Ori false gods?
Is there an efficient way to replace text matching the entire content of one file with the entire content of another file?
How do you say “buy” in the sense of “believe”?
what would be the configuration for mapStruct to stop mapping a DTO's super class's fields?
Why does this MapStruct generated class does not include import statement?JHipster EntityMapper interface (mapstruct): map a Spring projection interfacejava - MapStruct unable to map fields in base class in mapper functionMapStruct map correct instance of object based on target typeMapStruct - Wrong datatype is considered while generating the mapper implementation classMapstruct map one field to multiple target fields and vice versaMapStruct equivalent of hint(Dozer)?Ambiguous mapping methods using java MapstructMapstruct: How to map A extends SingleValue<T> to T and A extends SingleValue<T> to B extends SingleValue<T> with the same mapper?How to use mapstruct on the parent object to detect the right child mapper?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am having a DTOs class which is extending spring-hateoas
's ResourceSupport
class. The UserMinimalDto
is a DTO for User
entity.
So, for generating the mapper classes, I am using mapStruct.
@Data //from lambok
@EqualsAndHashCode(callSuper=false)
public class UserMinimalDto extends ResourceSupport
String firstName;
String lastName;
String email;
String uniqueId;
String profilePicUrl;
I am using ResourceSupport
to add hateoas links to the response from the controller.
The Mapper interface
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
But when I run mvn clean install
on the project, I am facing compilation error
Can't map property "org.springframework.hateoas.Link id" to
"java.lang.Integer id". Consider to declare/implement a mapping
method: "java.lang.Integer map(org.springframework.hateoas.Link
value)".
This is because the mapStruct
is trying the map the fields of ResourceSupport
.
Its works if:
- I remove extends ResourceSupport from UserMinimalDto
- I remove dtoToEntity(UserMinimalDto userMinimalDto); from mapper
interface
What would be the configuration to tell mapStruct
to not map the super class fields?
java mapping mapstruct
add a comment |
I am having a DTOs class which is extending spring-hateoas
's ResourceSupport
class. The UserMinimalDto
is a DTO for User
entity.
So, for generating the mapper classes, I am using mapStruct.
@Data //from lambok
@EqualsAndHashCode(callSuper=false)
public class UserMinimalDto extends ResourceSupport
String firstName;
String lastName;
String email;
String uniqueId;
String profilePicUrl;
I am using ResourceSupport
to add hateoas links to the response from the controller.
The Mapper interface
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
But when I run mvn clean install
on the project, I am facing compilation error
Can't map property "org.springframework.hateoas.Link id" to
"java.lang.Integer id". Consider to declare/implement a mapping
method: "java.lang.Integer map(org.springframework.hateoas.Link
value)".
This is because the mapStruct
is trying the map the fields of ResourceSupport
.
Its works if:
- I remove extends ResourceSupport from UserMinimalDto
- I remove dtoToEntity(UserMinimalDto userMinimalDto); from mapper
interface
What would be the configuration to tell mapStruct
to not map the super class fields?
java mapping mapstruct
add a comment |
I am having a DTOs class which is extending spring-hateoas
's ResourceSupport
class. The UserMinimalDto
is a DTO for User
entity.
So, for generating the mapper classes, I am using mapStruct.
@Data //from lambok
@EqualsAndHashCode(callSuper=false)
public class UserMinimalDto extends ResourceSupport
String firstName;
String lastName;
String email;
String uniqueId;
String profilePicUrl;
I am using ResourceSupport
to add hateoas links to the response from the controller.
The Mapper interface
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
But when I run mvn clean install
on the project, I am facing compilation error
Can't map property "org.springframework.hateoas.Link id" to
"java.lang.Integer id". Consider to declare/implement a mapping
method: "java.lang.Integer map(org.springframework.hateoas.Link
value)".
This is because the mapStruct
is trying the map the fields of ResourceSupport
.
Its works if:
- I remove extends ResourceSupport from UserMinimalDto
- I remove dtoToEntity(UserMinimalDto userMinimalDto); from mapper
interface
What would be the configuration to tell mapStruct
to not map the super class fields?
java mapping mapstruct
I am having a DTOs class which is extending spring-hateoas
's ResourceSupport
class. The UserMinimalDto
is a DTO for User
entity.
So, for generating the mapper classes, I am using mapStruct.
@Data //from lambok
@EqualsAndHashCode(callSuper=false)
public class UserMinimalDto extends ResourceSupport
String firstName;
String lastName;
String email;
String uniqueId;
String profilePicUrl;
I am using ResourceSupport
to add hateoas links to the response from the controller.
The Mapper interface
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
But when I run mvn clean install
on the project, I am facing compilation error
Can't map property "org.springframework.hateoas.Link id" to
"java.lang.Integer id". Consider to declare/implement a mapping
method: "java.lang.Integer map(org.springframework.hateoas.Link
value)".
This is because the mapStruct
is trying the map the fields of ResourceSupport
.
Its works if:
- I remove extends ResourceSupport from UserMinimalDto
- I remove dtoToEntity(UserMinimalDto userMinimalDto); from mapper
interface
What would be the configuration to tell mapStruct
to not map the super class fields?
java mapping mapstruct
java mapping mapstruct
edited Mar 26 at 20:22
Andronicus
7,48932035
7,48932035
asked Mar 24 at 7:11
TheCoderTheCoder
559423
559423
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In order to ignore fields on a case by case bases you can use Mapping#ignore
.
In your case it will look like:
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
User dtoToEntity(UserMinimalDto userMinimalDto);
In case you have a common interface / class for your entities you can use @MapperConfig
and define those exclusions.
It can look something like:
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface CommonMappingConfig
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
BaseEntity map(ResourceSupport resourceSupport);
@Mapper(config = CommonMappingConfig.class)
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
what would be theBaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?
– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extendResourceSupport
– Filip
Mar 24 at 10:52
add a comment |
It's because the model class has other set of fields than DTO
, and your mapper maps both ways. But that is pretty natural, dto doesn't have an id.
The workaround would be to exclude those fields from mapping for example by annotating id
and other fields in model class, that aren't in dto with: Mapping("this")
.
It's not completely related to the the model class i.eUser
here. If I removeextends ResourceSupport
fromUserMinimalDto
, the mapper maps both the way perfectly. It's theResourceSupport
causing the issue.
– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't requireResourceSupport
and they map the field both ways perfectly.
– TheCoder
Mar 24 at 9:44
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/3.0/"u003ecc by-sa 3.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%2f55321500%2fwhat-would-be-the-configuration-for-mapstruct-to-stop-mapping-a-dtos-super-clas%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In order to ignore fields on a case by case bases you can use Mapping#ignore
.
In your case it will look like:
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
User dtoToEntity(UserMinimalDto userMinimalDto);
In case you have a common interface / class for your entities you can use @MapperConfig
and define those exclusions.
It can look something like:
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface CommonMappingConfig
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
BaseEntity map(ResourceSupport resourceSupport);
@Mapper(config = CommonMappingConfig.class)
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
what would be theBaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?
– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extendResourceSupport
– Filip
Mar 24 at 10:52
add a comment |
In order to ignore fields on a case by case bases you can use Mapping#ignore
.
In your case it will look like:
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
User dtoToEntity(UserMinimalDto userMinimalDto);
In case you have a common interface / class for your entities you can use @MapperConfig
and define those exclusions.
It can look something like:
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface CommonMappingConfig
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
BaseEntity map(ResourceSupport resourceSupport);
@Mapper(config = CommonMappingConfig.class)
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
what would be theBaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?
– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extendResourceSupport
– Filip
Mar 24 at 10:52
add a comment |
In order to ignore fields on a case by case bases you can use Mapping#ignore
.
In your case it will look like:
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
User dtoToEntity(UserMinimalDto userMinimalDto);
In case you have a common interface / class for your entities you can use @MapperConfig
and define those exclusions.
It can look something like:
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface CommonMappingConfig
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
BaseEntity map(ResourceSupport resourceSupport);
@Mapper(config = CommonMappingConfig.class)
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
In order to ignore fields on a case by case bases you can use Mapping#ignore
.
In your case it will look like:
@Mapper
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
User dtoToEntity(UserMinimalDto userMinimalDto);
In case you have a common interface / class for your entities you can use @MapperConfig
and define those exclusions.
It can look something like:
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface CommonMappingConfig
@Mapping(target = "id", ignore = true)
@Mapping(target = "links", ignore = true)
BaseEntity map(ResourceSupport resourceSupport);
@Mapper(config = CommonMappingConfig.class)
public interface UserMinimalMapper
UserMinimalMapper INSTANCE = Mappers.getMapper(UserMinimalMapper.class) ;
UserMinimalDto entityToDto(User user);
User dtoToEntity(UserMinimalDto userMinimalDto);
answered Mar 24 at 10:25
FilipFilip
4,15631632
4,15631632
what would be theBaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?
– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extendResourceSupport
– Filip
Mar 24 at 10:52
add a comment |
what would be theBaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?
– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extendResourceSupport
– Filip
Mar 24 at 10:52
what would be the
BaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?– TheCoder
Mar 24 at 10:49
what would be the
BaseEntity
here? An interface/class implemented by all of my entity classes? or the DTO classes?– TheCoder
Mar 24 at 10:49
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extend
ResourceSupport
– Filip
Mar 24 at 10:52
It would be an interface / class implemented / extended by all your entity classes. The DTO classes extend
ResourceSupport
– Filip
Mar 24 at 10:52
add a comment |
It's because the model class has other set of fields than DTO
, and your mapper maps both ways. But that is pretty natural, dto doesn't have an id.
The workaround would be to exclude those fields from mapping for example by annotating id
and other fields in model class, that aren't in dto with: Mapping("this")
.
It's not completely related to the the model class i.eUser
here. If I removeextends ResourceSupport
fromUserMinimalDto
, the mapper maps both the way perfectly. It's theResourceSupport
causing the issue.
– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't requireResourceSupport
and they map the field both ways perfectly.
– TheCoder
Mar 24 at 9:44
add a comment |
It's because the model class has other set of fields than DTO
, and your mapper maps both ways. But that is pretty natural, dto doesn't have an id.
The workaround would be to exclude those fields from mapping for example by annotating id
and other fields in model class, that aren't in dto with: Mapping("this")
.
It's not completely related to the the model class i.eUser
here. If I removeextends ResourceSupport
fromUserMinimalDto
, the mapper maps both the way perfectly. It's theResourceSupport
causing the issue.
– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't requireResourceSupport
and they map the field both ways perfectly.
– TheCoder
Mar 24 at 9:44
add a comment |
It's because the model class has other set of fields than DTO
, and your mapper maps both ways. But that is pretty natural, dto doesn't have an id.
The workaround would be to exclude those fields from mapping for example by annotating id
and other fields in model class, that aren't in dto with: Mapping("this")
.
It's because the model class has other set of fields than DTO
, and your mapper maps both ways. But that is pretty natural, dto doesn't have an id.
The workaround would be to exclude those fields from mapping for example by annotating id
and other fields in model class, that aren't in dto with: Mapping("this")
.
answered Mar 24 at 7:15
AndronicusAndronicus
7,48932035
7,48932035
It's not completely related to the the model class i.eUser
here. If I removeextends ResourceSupport
fromUserMinimalDto
, the mapper maps both the way perfectly. It's theResourceSupport
causing the issue.
– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't requireResourceSupport
and they map the field both ways perfectly.
– TheCoder
Mar 24 at 9:44
add a comment |
It's not completely related to the the model class i.eUser
here. If I removeextends ResourceSupport
fromUserMinimalDto
, the mapper maps both the way perfectly. It's theResourceSupport
causing the issue.
– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't requireResourceSupport
and they map the field both ways perfectly.
– TheCoder
Mar 24 at 9:44
It's not completely related to the the model class i.e
User
here. If I remove extends ResourceSupport
from UserMinimalDto
, the mapper maps both the way perfectly. It's the ResourceSupport
causing the issue.– TheCoder
Mar 24 at 9:43
It's not completely related to the the model class i.e
User
here. If I remove extends ResourceSupport
from UserMinimalDto
, the mapper maps both the way perfectly. It's the ResourceSupport
causing the issue.– TheCoder
Mar 24 at 9:43
I have other DTOs and mappers which don't require
ResourceSupport
and they map the field both ways perfectly.– TheCoder
Mar 24 at 9:44
I have other DTOs and mappers which don't require
ResourceSupport
and they map the field both ways perfectly.– TheCoder
Mar 24 at 9:44
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%2f55321500%2fwhat-would-be-the-configuration-for-mapstruct-to-stop-mapping-a-dtos-super-clas%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