Skip to content

lagoshny/spring-data-rest-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo project to reproduce Data Rest JPA Bug

Build and start application

mvn spring-boot:start

To stop app run

mvn spring-boot:stop

Init 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"
}

Expected behaviour:

Spring Data REST converts author using URI to Entity object.

Actual behaviour:

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')"
}

How to fix

  1. In Spring Boot 4 uncomment @Bean in com.lagoshny.spring_data_rest_demo.config.AppConfig file 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.

  2. Downgrade Spring Boot to last 3.x.x version in pom.xml and restart application.

About

Demo project for demonstrate Spring Data Rest Bug

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages