question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Allow mapper to map instance to abstract class

See original GitHub issue

hello, 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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Kilrathcommented, Oct 10, 2018

I had wrote such a converter for our projects. Maybe I could add this to the project here?!

0reactions
Kilrathcommented, Jan 4, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found