Content-Length: 432300 | pFad | http://github.com/mapstruct/mapstruct/pull/3546

24 #2257 Adding abstract class mappers with defined constructor by TheAndreyy · Pull Request #3546 · mapstruct/mapstruct · GitHub
Skip to content

#2257 Adding abstract class mappers with defined constructor #3546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

TheAndreyy
Copy link

@TheAndreyy TheAndreyy commented Mar 4, 2024

For spring mappers you can inject components by constructor when it is defined, mapper implementation will call it's super constructor.

Adding calling super canonical costructor only for Spring mappers as decided in referenced issue (#2257) by project maintainers

@filiphr
Copy link
Member

filiphr commented Mar 10, 2024

Thanks for the PR @TheAndreyy. From what I could see this only works for spring. In order for us to be able to accept this we would need to have full support for the rest of the component models as well (for those where this is possible).

Is this something that you can work on to finish the PR?

@TheAndreyy
Copy link
Author

Hey @filiphr, thank for the review.

Yes, I'd be happy to implement this. Now it only works for Spring as you've designed it in this comment.

As I'm monstly fimiliar with Spring, I have to ask you for more requirements regarding other component models constructors. For example if I add this for "default" ComponentModel, getting Mapper instance like this Mappers.getMapper( MapperWithCanonicalConstructor.class ) won't work.

@filiphr
Copy link
Member

filiphr commented Mar 14, 2024

In that comment I was saying that it would be easy for Spring, but that we should make it work for all 😄.

As I'm monstly fimiliar with Spring, I have to ask you for more requirements regarding other component models constructors.

For the non default ones, I would say similar to Spring.

For the default component model we could do something similar like we are doing for the fields. i.e. if it is a mapper use Mappers.getMapper when calling the support, otherwise instantiate the class.

@TheAndreyy
Copy link
Author

TheAndreyy commented Mar 14, 2024

@filiphr Ok, I'll add it to other component models.

I'm not sure, I understand correctly your solution. You mean to create additional no-args-constructor that supplies super constructor with empty members, similar like in NewDatatypeFactoryConstructorFragment.ftl?
I see it something like this:

public MapperWithCanonicalConstructor() {
    super( field1Type.newInstance(), field2Type.newInstance() );
}

when calling the support

What do you mean by that?

@filiphr
Copy link
Member

filiphr commented Mar 16, 2024

I'm not sure, I understand correctly your solution. You mean to create additional no-args-constructor that supplies super constructor with empty members

Not sure if we are talking about the default component model now. If it is about the default I mean to generate something like:

public MyCustomMapperImpl() {
    super( Mappers.getMapper(MyOtherMapper.class), new MyUtils() );
}

basically we need to do exactly what we are doing when MyCustomMapper has @Mapper(uses = { MyOtherMapper.class, MyUtils.class })

What do you mean by that?

oops, I meant to say "When calling the supper", not idea why I said "support"

@TheAndreyy
Copy link
Author

@filiphr I've added changes as you requested. I've tried to satisfy requirements of a constructor for all component models, but not all have tests with constructor injection so I couldn't copy them ;) Waiting for your code suggestions!

@TheAndreyy
Copy link
Author

Hey @filiphr, hope you had good rest during Easter break. If you find some time for code review I'd be grateful 😄

@filiphr
Copy link
Member

filiphr commented Apr 27, 2024

Hey @filiphr, hope you had good rest during Easter break. If you find some time for code review I'd be grateful 😄

Sorry @TheAndreyy, I've been a bit busy before and after the Easter break and didn't have much time to review this. I'll try to check it out and provide feedback to you asap

@TheAndreyy
Copy link
Author

Hi, long time no see ;) I've added support for @Mapper(uses=.....).

Thanks for pointing this out @zyberzebra, I haven't used it before. In my opinion now it works more elegant - see test UserCanonicalConstructorWithUsesOtherMapper. Sorry I couldn't use your solution, a lot of other tests were failing and I wasn't able to fix it.

Waiting for review, I'm counting on you @filiphr that you find some time :)

@TheAndreyy
Copy link
Author

Hi @filiphr, I see I've missed to check code formatting, now pipeline should pass. Waiting for code review suggestions 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/mapstruct/mapstruct/pull/3546

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy