Build and start application
mvn spring-boot:startTo stop app run
mvn spring-boot:stopInit script created database and necessary tables with data.
Open HAL explorer and perform POST request to the task resource with the next data:
{
"number": 1,
"author": "http://localhost:8080/users/1",
"name": "Test"
}Spring Data REST converts author using URI to Entity object.
Spring Data REST throws exception:
{
"cause": {
"cause": null,
"message": "Cannot construct instance of `com.lagoshny.spring_data_rest_demo.db.User` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/users/1')\n at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #29] (through reference chain: com.lagoshny.spring_data_rest_demo.db.Task[\"author\"])"
},
"message": "JSON parse error: Cannot construct instance of `com.lagoshny.spring_data_rest_demo.db.User` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/users/1')"
}-
In Spring Boot 4 uncomment
@Beanincom.lagoshny.spring_data_rest_demo.config.AppConfigfile and restart app. Now Spring Data REST will use the right converter for hal request and author will be converted from URI to Entity object. -
Downgrade Spring Boot to last 3.x.x version in
pom.xmland restart application.