Affects: Spring Boot 2.2.2.RELEASE
consider a resource like this:
@RequestMapping(value = "/reservation",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
fun loadReservations(ReservationCriteria criteria) : List<Reservation> = service.loadReservations(criteria)
with request params container object as:
data class ReservationCriteria (
val hotelName:String,
val filter : Details
)
data class Details (
val type : String,
val stars : Int
)
With a request: /reservation?hotelName=myHotel
myHotel will be bound to hotelName in ReservationCriteria object.
But how can I bind parameters to the nested object Details?
I thought a request like: /reservation?hotelName=myHotel&filter.type=luxury&filter.stars=4
Does not seem to be working in the SB 2.2.2.RELEASE
The sub object reservationDateRange is always getting null values( for to and from as per the above mentioned question)
Here is a simple project with a test failing: https://github.com/piyushmor/spring-param-bug
Related StackOverflow discussion.
Comment From: rstoyanchev
Thanks for the report but, as per project guidelines for creating an issue, you need to edit the description in order to provide a self-sufficient explanation of the issue instead of linking to Stack Overflow. It is fine to provide references to a Stack Overflow discussions but only as further reference and not as a substitute for an issue description.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Comment From: piyushmor
@rstoyanchev , Sorry for not being able to work on it during the holiday season 😅. I have updated all the information. Do let me know if you need more.
Comment From: rstoyanchev
Kotlin data classes use constructor arguments while Data Binding typically depends on setters. So the failure isn't due to null fields in the nested object, but because of a failure to create the nested Object. Using the sample the following shows in the logging:
java.lang.NoSuchMethodException: org.pmor.springparambug.resource.NestedFilter.<init>()
Data Binding does support constructor arguments but not for nested objects.
So this is expected behavior. For data binding with nested Objects, you'll need to use Objects that support setters and getters.