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

Rest Client Reactive: Provide custom ObjectMapper in request scope #27203

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented 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 #26152
Relates #26988

@quarkus-bot quarkus-bot bot added the area/rest label Aug 9, 2022
@quarkus-bot

This comment has been minimized.

@Sgitario Sgitario force-pushed the contextresolver_restclient branch from 8cae241 to 57ce196 Compare August 10, 2022 05:02
@quarkus-bot

This comment has been minimized.

@Sgitario Sgitario force-pushed the contextresolver_restclient branch from 57ce196 to c9083d5 Compare August 25, 2022 11:56
@quarkus-bot

This comment has been minimized.

@Sgitario Sgitario force-pushed the contextresolver_restclient branch from c9083d5 to 2978c5f Compare August 26, 2022 05:11
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 Sgitario force-pushed the contextresolver_restclient branch from 2978c5f to d9a9b55 Compare August 26, 2022 07:17
@Sgitario Sgitario merged commit c4e9918 into quarkusio:main Aug 26, 2022
@quarkus-bot quarkus-bot bot added this to the 2.13 - main milestone Aug 26, 2022
@Sgitario Sgitario deleted the contextresolver_restclient branch August 26, 2022 10:21
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jan 18, 2023
After quarkusio#27203, we can customize the object mappers to be used by REST Client Reactive.
However, because of quarkusio#16368, the implementation was never picked up when the resteasy reactive jackson extension is in place. 
I tried to remove the ResteasyReactiveJacksonProviderDefinedBuildItem build item and surprisingly everything kept working fine (I verified the test that was added as part of  quarkusio#16368.

Fix quarkusio#23979
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jan 18, 2023
After quarkusio#27203, we can customize the object mappers to be used by REST Client Reactive.
However, because of quarkusio#16368, the implementation was never picked up when the resteasy reactive jackson extension is in place. 
I tried to remove the ResteasyReactiveJacksonProviderDefinedBuildItem build item and surprisingly everything kept working fine (I verified the test that was added as part of  quarkusio#16368.

Fix quarkusio#23979
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jan 18, 2023
After quarkusio#27203, we can customize the object mappers to be used by REST Client Reactive.
However, because of quarkusio#16368, the implementation was never picked up when the resteasy reactive jackson extension is in place. 
I tried to remove the ResteasyReactiveJacksonProviderDefinedBuildItem build item and surprisingly everything kept working fine (I verified the test that was added as part of  quarkusio#16368.

Fix quarkusio#23979
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jan 19, 2023
After quarkusio#27203, we can customize the object mappers to be used by REST Client Reactive.
However, because of quarkusio#16368, the implementation was never picked up when the resteasy reactive jackson extension is in place. 
I tried to remove the ResteasyReactiveJacksonProviderDefinedBuildItem build item and surprisingly everything kept working fine (I verified the test that was added as part of  quarkusio#16368.

Fix quarkusio#23979
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.

Resteasy Reactive: ContextResolver<ObjectMapper> not used
2 participants