-
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
Introduce support for ContextResolver<ObjectMapper> in server part of RESTEasy Reactive #26988
Conversation
… RESTEasy Reactive Relates to: quarkusio#26152
Would be good to have this in |
...quarkus/resteasy/reactive/jackson/deployment/processor/ResteasyReactiveJacksonProcessor.java
Show resolved
Hide resolved
ContextResolver<ObjectMapper> contextResolver = providers.getContextResolver(ObjectMapper.class, | ||
context.getResponseMediaType()); |
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's more of a general question but do you handle @ConstrainedTo
for providers in RESTEasy Reactive? (to constrain providers to server/client)
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.
That's an excellent question, unfortunately this is a limitation of the (pretty bad) JAX-RS Provider
API. If you look at javax.ws.rs.ext.Providers
, there is way to limit the results using the javax.ws.rs.RuntimeType
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.
But RESTEasy Classic implements it, I'm sure because I used this feature already.
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.
Implements what? The constraint? Are you sure?
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.
Support for @ConstrainedTo
. But maybe I misunderstood what you were saying.
Note that it doesn't mean you can't merge this PR, it's just a question that came to mind.
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.
I don't see @ConstrainedTo
being taken into account anywhere in RESTEasy Classic. Do you have an example suggesting otherwise?
Unless there are any objections, I am going to merge this |
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
With these changes, we can now register custom object mappers when creating a client programmatically: ``` clientAllowsUnknown = RestClientBuilder.newBuilder() .baseUrl(new URL(wireMockServer.baseUrl())) .register(ClientObjectMapperUnknown.class) .build(MyClient.class); ``` where ClientObjectMapperUnknown is: ``` public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> { @OverRide public ObjectMapper getContext(Class<?> type) { return new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } } ``` I implemented this feature by injecting the rest client context via the interface ClientRestHandler. Then, the rest client context has registered all the context resolvers, so the jackson message reader/writer can get the custom object mappers. Fix quarkusio#26152 Relates quarkusio#26988
Relates to: #26152