Private mapper do not work when the parent class implement an interface.
See original GitHub issueDescribe the bug
I have the basic setup:
internal sealed class UserWithClaims : IUser
{
private readonly IdentityUser snapshot;
public UserWithClaims(IdentityUser user, IReadOnlyList<Claim> claims, IReadOnlySet<string> roles)
{
// Clone the user so that we capture the previous values, even when the user is updated.
snapshot = Mapper.IdentityUserToIdentityUser(user);
}
[Mapper(UseDeepCloning = true)]
private static partial class Mapper
{
public static partial IdentityUser IdentityUserToIdentityUser(IdentityUser source);
}
}
But the generated code does not add the namespace to the IUser
interface, which is defined in another namespace. So the follow code is generated:
#nullable enable
namespace Notifo.Identity
{
internal sealed class UserWithClaims : IUser
{
private static partial class Mapper
{
public static partial global::Microsoft.AspNetCore.Identity.IdentityUser IdentityUserToIdentityUser(global::Microsoft.AspNetCore.Identity.IdentityUser source)
{
var target = new global::Microsoft.AspNetCore.Identity.IdentityUser();
target.Id = source.Id;
...
return target;
}
}
}
}
Expected behavior The implementing or base classes do not need to be copied to the generated code. if you want to copy that, add the namespaces.
Environment (please complete the following information):
- Mapperly Version: 2.8.0
- .NET Version: 7.0
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 2 months ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Compilation failure when mapper interface is a private ...
When a private nested interface is declared as a @Mapper, three compilation warnings are emitted in the generated class. It's not completely ...
Read more >Mapper not generating correctly the Implementation class
I'm working in spring boot with Mappstruct and Lombok. When I use the Mapper anotation to auto implement the mapper class, the anotation...
Read more >Should i implement same interface in derived class?
For most intents and purposes you don't need to implement an interface on the derived class. However there is a difference between the...
Read more >Interfaces and Inheritance in Java
Multiple Inheritance is not supported by class because of ambiguity. In the case of interface, there is no ambiguity because the implementation ...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
A generic type is a class or interface that is parameterized over types. ... Now the problem with above implementation is that it...
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 FreeTop 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
Top GitHub Comments
Yes! Afaik Mapperly can map most types.
Example
Generated code
This bug has been fixed in
2.9.0-next.4
See #548 for details.