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

Introduce support for ContextResolver<ObjectMapper> in server part of RESTEasy Reactive #26988

Merged
merged 1 commit into from Aug 5, 2022

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jul 28, 2022

Relates to: #26152

@geoand
Copy link
Contributor Author

geoand commented Aug 1, 2022

Would be good to have this in 2.11.2.Final

Comment on lines +100 to +101
ContextResolver<ObjectMapper> contextResolver = providers.getContextResolver(ObjectMapper.class,
context.getResponseMediaType());
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@geoand geoand Aug 4, 2022

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?

Copy link
Member

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.

Copy link
Contributor Author

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?

@geoand
Copy link
Contributor Author

geoand commented Aug 4, 2022

Unless there are any objections, I am going to merge this

@geoand geoand merged commit ffe2239 into quarkusio:main Aug 5, 2022
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Aug 5, 2022
@geoand geoand deleted the #26152 branch August 5, 2022 05:48
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Aug 9, 2022
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
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Aug 10, 2022
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
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Aug 25, 2022
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
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Aug 26, 2022
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
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Aug 26, 2022
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
fercomunello pushed a commit to fercomunello/quarkus that referenced this pull request Aug 31, 2022
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
evanchooly pushed a commit to nenros/quarkus that referenced this pull request Sep 8, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants