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

Support nested Java records for AbstractNestablePropertyAccessor #28996

Closed
benneq opened this issue Aug 22, 2022 · 2 comments
Closed

Support nested Java records for AbstractNestablePropertyAccessor #28996

benneq opened this issue Aug 22, 2022 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@benneq
Copy link

benneq commented Aug 22, 2022

Affects: 6.0.0.M5 (but also 5.x)


I'm trying to get an immutable representation of the query parameters in my @RestController, like this:

@RestController
public class MyController {
	
	@RequestMapping("/foo")
	public void foo(A a) {
	}
	
	record A(String s, B b) {
	}

	record B(Integer i) {
	}
}

For single-level query params this works as expected: GET /foo?s=xyz

But as soon as I try to set b.i using GET /foo?b.i=42 it will throw an exception, because AbstractNestablePropertyAccessor is looking for a default constructor:

java.lang.NoSuchMethodException: com.example.demo.MyController$B.<init>()
	at java.base/java.lang.Class.getConstructor0(Class.java:3585) ~[na:na]
	at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[na:na]
	at org.springframework.beans.AbstractNestablePropertyAccessor.newValue(AbstractNestablePropertyAccessor.java:910) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractNestablePropertyAccessor.createDefaultPropertyValue(AbstractNestablePropertyAccessor.java:883) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractNestablePropertyAccessor.setDefaultValue(AbstractNestablePropertyAccessor.java:870) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:842) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:816) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:257) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:889) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.validation.DataBinder.doBind(DataBinder.java:780) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:207) ~[spring-web-6.0.0-M5.jar:6.0.0-M5]
	at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:129) ~[spring-web-6.0.0-M5.jar:6.0.0-M5]

Thanks for your help!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 22, 2022
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 23, 2022
@sbrannen sbrannen added this to the Triage Queue milestone Aug 23, 2022
@rstoyanchev
Copy link
Contributor

@jhoeller this looks like it should be covered/superseded by #20806? Maybe just an extra comment there to ensure it works for records too.

@rstoyanchev rstoyanchev removed this from the Triage Queue milestone Jan 20, 2023
@rstoyanchev rstoyanchev self-assigned this Jun 27, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 27, 2023
@rstoyanchev
Copy link
Contributor

This is covered by #20806.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@rstoyanchev rstoyanchev added the status: superseded An issue that has been superseded by another label Jun 27, 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) in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants