I've migrated my Spring Boot 3.5.8 application that uses spring-data-rest (@RepositoryRestResource) to Spring Boot 4.0.0 (using Jackson 3).
I used to be able to create entities with a HTTP Post Request and assign the entity to its relationship with a simple post request. For example, I have an order with order-item entities and I want to add an order item to the entity order. The following call used to work when I was using Spring Boot 3.5.8 ... but it does not with SB 4.0.0
POST http://localhost:8080/myapp/order-item
Content-Type: application/json
{
"name": "item name",
"order": "/order/1"
}
This does not work anymore. All my similar post endpoints are currently broken. The only thing that works for now is to change my payload to:
POST http://localhost:8080/myapp/order-item
Content-Type: application/json
{
"name": "item name",
"order": {
"id": 1
}
}
Regards
Comment From: fdlessard
This is the error response I get :
{
"detail": "Failed to read request",
"instance": "...",
"status": 400,
"title": "Bad Request"
}
and in the logs i see:
.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `....` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('/order/1')]
Comment From: philwebb
Could you please provide a sample application that works with 3.x and fails with 4.x. This will help us track down if this is a Spring Boot issue, a Spring Data REST issue or a problem elsewhere.
Comment From: fdlessard
I've created the following 2 projects that shows that URI String in spring datat rest jpa post request (HATEOS) are not working anymore on in SB 4.0.0 and the same Post Request worked in SB 3.5.8.
https://github.com/fdlessard/spring-boot-order-rest-jpa-358 https://github.com/fdlessard/spring-boot-order-rest-jpa-4
Regards
Comment From: philwebb
I'm still trying to work out why, but it appears that AssociationUriResolvingDeserializerModifier is no longer being used.
Comment From: philwebb
Finally tracked it down. In 4.0 the AlpsJsonHttpMessageConverter is being used. It turns out this has already been fixed in https://github.com/spring-projects/spring-data-rest/issues/2533 (issue https://github.com/spring-projects/spring-data-commons/issues/3418 was also marked as a duplicate and has more details).