Skip to content

[spring-server] default data fetcher should use Jackson object mapper from spring context #524

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

Closed
dariuszkuc opened this issue Dec 20, 2019 · 0 comments · Fixed by #525
Closed
Assignees
Labels
type: bug Something isn't working
Milestone

Comments

@dariuszkuc
Copy link
Collaborator

Library Version
2.0.0-SNAPSHOT

Describe the bug
Currently it is not possible to provide custom Jackson object mapper (e.g. one that includes java date time module) to be used by default function data fetcher (see code below). In order to use custom object mapper users have to create their own instance of data fetcher factory provider.

open class KotlinDataFetcherFactoryProvider {

    private val defaultObjectMapper = jacksonObjectMapper()

    /**
     * Retrieve instance of [DataFetcherFactory] that will be used to resolve target function.
     *
     * @param target target object that performs the data fetching or NULL if target object should be dynamically
     * retrieved during data fetcher execution from [graphql.schema.DataFetchingEnvironment]
     * @param kFunction Kotlin function being invoked
     */
    open fun functionDataFetcherFactory(target: Any?, kFunction: KFunction<*>): DataFetcherFactory<Any> =
            DataFetcherFactories.useDataFetcher(
                FunctionDataFetcher(
                        target = target,
                        fn = kFunction,
                        objectMapper = defaultObjectMapper)
            )
...
}

To Reproduce
Create custom ObjectMapper in spring context (or customize it by using Jackson2ObjectMapperBuilderCustomizer) and notice that it is ignored by KotlinDataFetcherFactoryProvider as it creates its own instance anyway.

Expected behavior
ObjectMapper from spring application context should be used by default data fetcher.

@dariuszkuc dariuszkuc added the type: bug Something isn't working label Dec 20, 2019
@dariuszkuc dariuszkuc added this to the 2.0.0 milestone Dec 20, 2019
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Dec 20, 2019
… from spring context

Currently it is not possible to provide custom Jackson object mapper (e.g. one that includes java date time module) to be used by default function data fetcher. In order to use custom object mapper users have to create their own instance of data fetcher factory provider. This change updates the data fetcher factory provider to accept an instance of object mapper that will be used by the function data fetcher.

Resolves: ExpediaGroup#524
@dariuszkuc dariuszkuc self-assigned this Dec 27, 2019
smyrick pushed a commit that referenced this issue Dec 27, 2019
… from spring context (#525)

* [spring-server] default data fetcher should use Jackson object mapper from spring context

Currently it is not possible to provide custom Jackson object mapper (e.g. one that includes java date time module) to be used by default function data fetcher. In order to use custom object mapper users have to create their own instance of data fetcher factory provider. This change updates the data fetcher factory provider to accept an instance of object mapper that will be used by the function data fetcher.

Resolves: #524

* unit test for verifying proper object mapper is used

* convert KotlinDataFetcherFactoryProvider to interface

Previous default implmenetation is now renamed to SimpleKotlinDataFetcherFactoryProvider.

* add integration test to verify custom jackson bindings work with function data fetcher

* remove unnecessary val definition
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Aug 5, 2022
… from spring context (ExpediaGroup#525)

* [spring-server] default data fetcher should use Jackson object mapper from spring context

Currently it is not possible to provide custom Jackson object mapper (e.g. one that includes java date time module) to be used by default function data fetcher. In order to use custom object mapper users have to create their own instance of data fetcher factory provider. This change updates the data fetcher factory provider to accept an instance of object mapper that will be used by the function data fetcher.

Resolves: ExpediaGroup#524

* unit test for verifying proper object mapper is used

* convert KotlinDataFetcherFactoryProvider to interface

Previous default implmenetation is now renamed to SimpleKotlinDataFetcherFactoryProvider.

* add integration test to verify custom jackson bindings work with function data fetcher

* remove unnecessary val definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
1 participant