Feature Request: Allow mapper to map instance to abstract class
See original GitHub issuehello, I want to map a object to a abstract class (eg, interface) instead of concrete class.
interface IAccount {
public String getName();
public String getSubject();
}
class Account {
String name;
String subject;
String password;
// getter setter ...
}
then, map the Account
to interface IAccount
by creating a dynamic proxy object to implement it.
Do we need this ?
I think it’s very useful. cause we use interfaces to pass some immutable variables btw tiers, such as DTO, we deserialize a JSON to an interface
to initialize DTO by create a dynamic proxy. and do so to response a JSON.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Support for abstract class mapping or classes with base class
The way you'd currently do this is to declare the mapping methods for cat/dog or man/woman to let them be generated and implement...
Read more >Map abstract class to DTO with MapStruct - java - Stack Overflow
This way MapStruct will use this method to create Person instance and than map the properties like usual. You can find more about...
Read more >Guide to MapStruct in Java - Advanced Mapping Library
So far, we've been accessing the generated mappers via the getMapper() method: DoctorMapper INSTANCE = Mappers.getMapper(DoctorMapper.class);.
Read more >MapStruct 1.5.3.Final Reference Guide
This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar.
Read more >MapStruct — Advanced Concepts and Dependency Injection
When not using a DI framework, Mapper instances can be retrieved via the org.mapstruct.factory.Mappers class. Just invoke the getMapper() method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had wrote such a converter for our projects. Maybe I could add this to the project here?!
Not sure if you looking for such kind of converter (https://gitlab.com/kilrath987/modelmapper/-/blob/master/src/main/java/org/kilrath/modelmapper/converter/AbstractTypeConverter.java), but have a look here. If you need more explanation, don’t hesitate to contact me.