-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allows customizing the ObjectMapper in REST Client Reactive Jackson #35025
Conversation
@geoand let me know what you think about this solution:
|
To be honest, I don't see why would call the annotation |
|
What I am saying is that I prefer we have a specific annotation, just like we do (as you pointed out) for Also keep in mind, that the name |
Do you mean to reduce the scope of the feature to only support object mappers? And so, provide a specific annotation If so, I encounter the current solution as much more powerful. The existing annotation allows adding beans to the client context in a generic way. Though, we could discuss the name (perhaps I also like having something |
Yes
The problem is that these non-Quarkus APIs are very arcance to use (hence the original issue in the first place). Having said that, if you want to keep the "infrastructure" you created to support it and simply not "expose" it, that's fine with me (as long as the design decision is mentioned properly in the code comments) |
What non-Quarkus APIs do you mean? The Providers interface and ContextResolver are coming from the JAX-RS specification, so the more we are integrated with it, the better (because users already know it). Moreover, we're documenting this use case, so from a user's perspective, it does exist and it's up to the users, to use it or not. |
These are what I am talking about
We already have integration with them. What I am saying that is they are terrible APIs and we should not be trying to make things easier for users by exposing them more. |
This is a biased argument ;) But yes, I agree with you that having to do something like this I've already updated the solution and will update the pull request once all the checks are green in my local. |
It is :). But I also get to see 10s of issues, chats, SO questions and reproducers everyday so it's not a totally uninformed opinion :) |
PR updated and PR title/description updated @geoand |
|
||
@ClientObjectMapper <1> | ||
static ObjectMapper objectMapper(ObjectMapper defaultObjectMapper) { <2> | ||
return defaultObjectMapper.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention here that users should NEVER
change the defaultObjectMapper
but instead always use copy
if they pan to inherit the default settings.
The same goes for the Javadoc of @ClientObjectMapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
...t/src/main/java/io/quarkus/rest/client/reactive/deployment/ClientContextResolverHandler.java
Show resolved
Hide resolved
...e/src/main/java/io/quarkus/rest/client/reactive/runtime/ResteasyReactiveContextResolver.java
Show resolved
Hide resolved
PR updated with your comments. |
|
||
<1> The method must be annotated with `@ClientObjectMapper`. | ||
<2> It's must be a static method. Also, the parameter `defaultObjectMapper` will be resolved via CDI. If not found, it will throw an exception at runtime. | ||
<3> In this example, we're creating a copy of the default object mapper. You should *NEVER* modify the default object mapper, but creating a copy instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3> In this example, we're creating a copy of the default object mapper. You should *NEVER* modify the default object mapper, but creating a copy instead. | |
<3> In this example, we're creating a copy of the default object mapper. You should *NEVER* modify the default object mapper, but create a copy instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
* {@code | ||
* @ClientObjectMapper | ||
* static ObjectMapper objectMapper(ObjectMapper defaultObjectMapper) { | ||
* return defaultObjectMapper.copy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably makes sense to also change something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it makes sense. Added.
The REST Client Reactive supports adding a custom ObjectMapper to be used only the Client using the annotation `@ClientObjectMapper`. A simple example is to provide a custom ObjectMapper to the REST Client Reactive Jackson extension by doing: ```java @path("/extensions") @RegisterRestClient public interface ExtensionsService { @get Set<Extension> getById(@QueryParam("id") String id); @ClientObjectMapper <1> static ObjectMapper objectMapper(ObjectMapper defaultObjectMapper) { <2> return defaultObjectMapper.copy() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(DeserializationFeature.UNWRAP_ROOT_VALUE); } } ``` <1> The method must be annotated with `@ClientObjectMapper`. <2> It's must be a static method. Also, the parameter `defaultObjectMapper` will be resolved via CDI. If not found, it will throw an exception at runtime. Fix quarkusio#23979
PR updated again with your latest comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
🙈 The PR is closed and the preview is expired. |
✔️ The latest workflow run for the pull request has completed successfully. It should be safe to merge provided you have a look at the other checks in the summary. |
The REST Client Reactive supports adding a custom ObjectMapper to be used only the Client using the annotation
@ClientObjectMapper
.A simple example is to provide a custom ObjectMapper to the REST Client Reactive Jackson extension by doing:
<1> The method must be annotated with
@ClientObjectMapper
.<2> It's must be a static method. Also, the parameter
defaultObjectMapper
will be resolved via CDI. If not found, it will throw an exception at runtime.Closes #23979