Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Data Rest using Jackson snake_case naming strategy [DATAREST-1361] #1724

Open
spring-projects-issues opened this issue Apr 5, 2019 · 1 comment
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 5, 2019

hypr2771 opened DATAREST-1361 and commented

What

Using :

  • spring.jackson.property-naming-strategy: SNAKE_CASE
  • spring-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 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'){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 @Entity named 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#updateBuilder which 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 is snake_case.

Whereas when looking for org.springframework.data.mapping.model.BasicPersistentEntity#getPersistentProperty, it cannot find it since in org.springframework.data.mapping.model.BasicPersistentEntity#propertyCache, the name is camelCase.

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#create test case


Affects: 3.1.6 (Lovelace SR6)

Reference URL: https://github.com/hypr2771/naming-strategy-issue

@MarcusAdriano
Copy link

@MarcusAdriano MarcusAdriano commented Dec 17, 2021

Hello,
Are there updates about this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants