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

property-naming-strategy (and other jackson configurations) not respected #552

Closed
facup94 opened this issue Aug 17, 2023 · 5 comments · Fixed by #846
Closed

property-naming-strategy (and other jackson configurations) not respected #552

facup94 opened this issue Aug 17, 2023 · 5 comments · Fixed by #846
Labels
status: under consideration The issue is being considered, but has not been accepted yet

Comments

@facup94
Copy link

facup94 commented Aug 17, 2023

Expected Behavior

Micronaut Serialization module should respect Jackson property naming strategy settings (from application.yml) when serializing/deserializing POJOs

Actual Behaviour

Micronaut ignores Jackson settings

Steps To Reproduce

  1. create an app with jackson features
    mn create-app --build=gradle --jdk=17 --lang=java --test=junit --features=serialization-jackson,jackson-databind com.example.demo
  2. Add a controller with an endpoint that receives a POJO
// HelloController.java
@Controller
public class HelloController {
    @Post("/hello1")
    @Produces(MediaType.APPLICATION_JSON)
    public String index(@Body Hello1Request req) {
        return "Hello1, " + req.firstName();
    }
}

// Hello1Request.java
@Serdeable
public class Hello1Request {
    private final String firstName;

    public Hello1Request(final String firstName) {
        this.firstName = firstName;
    }

    public String firstName() {
        return firstName;
    }
}
  1. Add jackson.property-naming-strategy: SNAKE_CASE to application.yml
  2. Start the app
  3. Send a request using snake case: curl -X POST 'http://localhost:8080/hello1' -H 'Content-Type: application/json' -d '{"first_name": "John"}'
  4. Receive error: {"message":"Bad Request","_links":{"self":[{"href":"/hello1","templated":false}]},"_embedded":{"errors":[{"message":"Failed to convert argument [req] for value [null] due to: Unable to deserialize type [Hello1Request req]: Null argument specified for [firstName]. If this argument is allowed to be null annotate it with @Nullable","path":"/req"}]}}%
  5. Send a request using lower camel case: curl -X POST 'http://localhost:8080/hello1' -H 'Content-Type: application/json' -d '{"firstName": "John"}'
  6. receive OK response: Hello1, John

Environment Information

  • macOS Monterrey 12.6.6
  • Java 17
  • Micronaut 3.10.1

Example Application

No response

Version

3.10.1

@sdelamo
Copy link
Contributor

sdelamo commented Aug 18, 2023

you should not use both features serialization-jackson and jackson-databind

With Micronaut Framework 4.0, you must choose which serialization implementation you want..

I don't expect Micronaut Serialisation to use Jackson configuration such as jackson.property-naming-strategy: SNAKE_CASE

You can access the Micronaut Serialization configuration reference and Micronaut Serialization docs.

@sdelamo sdelamo transferred this issue from micronaut-projects/micronaut-core Aug 18, 2023
@sdelamo sdelamo moved this to Ready for Review in 4.0.5 Release Aug 18, 2023
@sdelamo sdelamo moved this from Ready for Review to Todo in 4.0.5 Release Aug 18, 2023
@facup94
Copy link
Author

facup94 commented Aug 21, 2023

you should not use both features serialization-jackson and jackson-databind

With Micronaut Framework 4.0, you must choose which serialization implementation you want..

I don't expect Micronaut Serialisation to use Jackson configuration such as jackson.property-naming-strategy: SNAKE_CASE

You can access the Micronaut Serialization configuration reference and Micronaut Serialization docs.

The issue I reported was for Micronaut 3.10.1 but thanks for your response.

I understand Micronaut Serialization does not have a configuration for naming strategy then

@sdelamo
Copy link
Contributor

sdelamo commented Aug 24, 2023

I understand Micronaut Serialization does not have a configuration for naming strategy then

I don't think we do. Do you know @yawkat ?

@graemerocher
Copy link
Contributor

currently it can be done on an individual type level but not globally no

@sdelamo sdelamo removed this from 4.0.6 Release Aug 31, 2023
@graemerocher graemerocher added the status: under consideration The issue is being considered, but has not been accepted yet label Oct 20, 2023
@sdelamo sdelamo removed this from 4.2.0 Release Nov 12, 2023
@sdelamo sdelamo removed this from 4.3.0 Release Jan 26, 2024
@sdelamo sdelamo removed this from 4.4.0 Release Apr 16, 2024
@abishai
Copy link

abishai commented May 21, 2024

We have even worse issue with Micronaut Serialization feature. We have JDBI as a ResultSet to POJO mapper and extensively using PG json functions. The problem is databases are usually snake cased, so we are injecting a copy of Jackson ObjectMapper with custom SNAKE_CASE strategy in Micronaut3 microservices.

With Micronaut's ObjectMapper is totally impossible by design (it reads @Serdeable annotation to determine strategy - and we use default for anything except database interaction).

Can we get back the ability to globally override strategy for concrete ObjectMapper instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: under consideration The issue is being considered, but has not been accepted yet
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants