In Spring Boot 2.5.2, something is broken with Jackson, when using @RepositoryRestResource
to POST a new entity into the DB.
In SB v2.4.8 the following works OK:
import lombok.Data;
@Data
@Entity
public class CollectionExercise {
@Id private UUID id;
@ManyToOne private Survey survey;
}
@Data
@Entity
public class Survey {
@Id private UUID id;
@OneToMany(mappedBy = "survey")
private List<CollectionExercise> collectionExercises;
}
@RepositoryRestResource
public interface CollectionExerciseRepository
extends PagingAndSortingRepository<CollectionExercise, UUID> {}
Then, I can do this: POST http://localhost:8080/collectionExercises
with the following body:
{
"id": "246b3010-6373-421d-9e9f-ed1366f17385",
"survey": "surveys/5af5b469-0cd3-45e9-9692-5253917e3f62"
}
In SB v2.5.2 I get the following exception:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `bla.blala.Survey` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/surveys/5af5b469-0cd3-45e9-9692-5253917e3f62')
Downgrading to SB 2.4.8 works fine.
Comment From: wilkinsona
Thanks for the report. @RepositoryRestResource
is part of Spring Data REST which is managed as a separate project. If you believe you've found a bug with it, please open a Spring Data REST issue and provide a complete and minimal sample that reproduces the problem. If you've already done some analysis and believe that the problem is caused by Spring Boot's configuration of Spring Data REST, please let us know and we can take another look.