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

Jackson: custom ObjectMapper not delegated to MicroProfile RestClient #39981

Closed
nimo23 opened this issue Apr 10, 2024 · 7 comments
Closed

Jackson: custom ObjectMapper not delegated to MicroProfile RestClient #39981

nimo23 opened this issue Apr 10, 2024 · 7 comments
Labels
area/jackson Issues related to Jackson (JSON library) kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@nimo23
Copy link
Contributor

nimo23 commented Apr 10, 2024

Describe the bug

I customized the Quarkus Jackson Object Mapper:

@Singleton
@JBossLog
public class MyMapper implements ObjectMapperCustomizer {

	public void customize(ObjectMapper mapper) {
            mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
	}

}

According to #12104 (comment), the

RestClientBuilder.newBuilder() or QuarkusRestClientBuilder.newBuilder() (I tried both) should use my customized ObjectMapper. However, this is not the case as I get the exception:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 
Unrecognized field "password" (class app.User), not marked as ignorable (one known property: "name"])

Expected behavior

My custom "Quarkus Jackson Object Mapper" should be delegated to RestClient when built using RestClientBuilder.newBuilder() or QuarkusRestClientBuilder.newBuilder().

Actual behavior

My custom "Quarkus Jackson Object Mapper" is not delegated to RestClient when built using RestClientBuilder.newBuilder() or QuarkusRestClientBuilder.newBuilder().

How to Reproduce?

  1. Customize Jackson Object Mapper (e.g. to use disable FAIL_ON_UNKNOWN_PROPERTIES)
  2. Build RestClient by using (a) RestClientBuilder.newBuilder() and (b) QuarkusRestClientBuilder.newBuilder().
  3. Make a Client GET-Request from a java record such as:
    public record User(@JsonProperty("name") String name) {}
  4. You will see, that the custom Jackson mapper is not used for the RestClient.

Output of uname -a or ver

No response

Output of java -version

openjdk version "21.0.2" 2024-01-16

Quarkus version or git rev

3.9.2

Build tool (ie. output of mvnw --version or gradlew --version)

maven

Additional information

No response

@nimo23 nimo23 added the kind/bug Something isn't working label Apr 10, 2024
@quarkus-bot quarkus-bot bot added the area/jackson Issues related to Jackson (JSON library) label Apr 10, 2024
Copy link

quarkus-bot bot commented Apr 10, 2024

/cc @geoand (jackson), @gsmet (jackson)

@geoand
Copy link
Contributor

geoand commented Apr 10, 2024

This is interesting indeed. Can you attach a sample application that behaves as you describe so we can dig into it?

Thanks

@geoand
Copy link
Contributor

geoand commented Apr 10, 2024

I would also like you know which REST Client extension you are using

@nimo23
Copy link
Contributor Author

nimo23 commented Apr 10, 2024

I use the the following quarkus 3.9.2 dependencies:

  • quarkus-rest-jackson
  • quarkus-rest-client-jackson

from my pom.xml:

..
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>

With the above dependency, the Microprofile Rest Client-extension (microprofile-rest-client-api-3.0.1.jar) is used.

@geoand
Copy link
Contributor

geoand commented Apr 10, 2024

Okay, please attach a sample application in that case so I can try it out.

@geoand geoand added triage/needs-feedback We are waiting for feedback. triage/needs-reproducer We are waiting for a reproducer. and removed triage/needs-feedback We are waiting for feedback. labels Apr 10, 2024
@nimo23
Copy link
Contributor Author

nimo23 commented Apr 10, 2024

I found the reason when creating the reproducer. It was my fault, I had accidentally used another default mapper (with mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) instead of using the Quarkus managed mapper. Using the quarkus managed mapper solves this issue.

So there is no bug here.

@nimo23 nimo23 closed this as completed Apr 10, 2024
@geoand
Copy link
Contributor

geoand commented Apr 10, 2024

Thanks for the update

@geoand geoand added triage/invalid This doesn't seem right and removed triage/needs-reproducer We are waiting for a reproducer. labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants