spring-projects / spring-projects/spring-data-rest
Spring Data Rest using Jackson snake_case naming strategy [DATAREST-1361]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
hypr2771 opened DATAREST-1361 and commented
What
Using :
spring.jackson.property-naming-strategy: SNAKE_CASEspring-boot-starter-data-rest
I run into a
`
JSON parse error: Cannot construct instance of
net.bugreport.domain.entities.SomethingCamelCase(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('/something_camel_cases/1'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance ofnet.bugreport.domain.entities.SomethingCamelCase(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('/something_camel_cases/1'){quote`}What I expect to be able to do the following :
{{POST /something_containing_camel_cases
{
"something_camel_case": "/something_camel_cases/1"
}
}}while having my
@Entitynamed according to Java conventions (camelCase)Done so far
I set up a small GitHub repository to give a minimal reproducible example : https://github.com/hypr2771/naming-strategy-issue.
I analyzed
org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.AssociationUriResolvingDeserializerModifier#updateBuilderwhich is responsible for my issue :Indeed, when getting the
com.fasterxml.jackson.databind.deser.SettableBeanProperty, the name of the property is its JSON name, which issnake_case.Whereas when looking for
org.springframework.data.mapping.model.BasicPersistentEntity#getPersistentProperty, it cannot find it since inorg.springframework.data.mapping.model.BasicPersistentEntity#propertyCache, the name iscamelCase.Code
As code is pretty heavy, containing
pom.xml, few classes and their repositories, a test case and the@SpringBootApplication, naming strategy and a data set, I set up a GitHub repository to store it.Repository on GitHub is available here for anyone to fork and get the error.
You simply have to run the
net.bugreport.domain.repositories.SomethingContainingCamelCaseRepositoryTest#createtest case
Affects: 3.1.6 (Lovelace SR6)
Reference URL: https://github.com/hypr2771/naming-strategy-issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.