Skip to content
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

Publish events with generic parameter without creating wrapper event [SPR-15346] #19909

Closed
spring-projects-issues opened this issue Mar 14, 2017 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression)

Comments

@spring-projects-issues
Copy link
Collaborator

Patrick Beaumont opened SPR-15346 and commented

As seen in page Better application events in Spring Framework 4.2, we cannot publish event without creating a class that would resolve generics parameters, due to type erasure.

It seems that it might be resolved with the ResolvableType, in the PayloadApplicationevent#getResolvableType().

Currently, we have

@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getPayload()));
}

which resolves correctly events in the form

MyEvent extends GenericMyEvent<T>

With something like the following, I was able to have it work in our project:

 
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forClassWithGenerics(payloadClass, ResolvableType.forInstance(payloadEntity)));
}

Affects: 4.3.5

1 votes, 2 watchers

@spring-projects-issues
Copy link
Collaborator Author

gtxx commented

+1 for this feature.
In my project, there are dozens of entity class, and I'd like to publish entity-create/ entity-update/ entity-delete event for each entity.
With this feature, I can publish generic event in generic service, that will reduce a lot boilerplate code.

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) and removed type: enhancement A general enhancement labels Jan 11, 2019
@snicoll
Copy link
Member

snicoll commented Sep 19, 2023

It's hard to understand what you mean as you didn't share where payloadClass and payloadEntity come from. We've improved this area of the framework recently, see #24599.

I am going to close this but if you believe this is still a problem and can share more details we can reopen of course.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression)
Projects
None yet
Development

No branches or pull requests

2 participants