Custom implementation of convertValue for input types #549
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use Jackson's
convertValue
to convert theMap
of input values created bygraphql-java
to a Java class for ease-of-use in data fetchers.Using Jackson's
convertValue
has always been problematic. It serializes the inputMap
and then deserializes it again into the targetClass
. In this process, it doesn't know thatgraphql-java
already took care of deserializing scalar values.This means the following happened:
Query input (as String)
-> deserialized (using scalars) toMap
bygraphql-java
-> Jackson serializes the value again, without using scalars, and deserializes to aClass
, again without using scalars.In most cases, this happened to work, because Jackson could "accidentally" successfully serialize/deserialize to the same value. In some cases, such as more complex scalars (e.g. data/time), this didn't result in the correct value.
Even though it worked "most of the time", it has always been fundamentally incorrect.
Changes in this PR
In this PR a custom "converter" is added. Note that the converter only maps a
Map
to a Java type, it doesn't do any deserialization. The deserialization is done bygraphql-java
.It accounts for both Java and Kotlin classes because they are instantiated differently through reflection.
We already had good test coverage for
@InputArgument
and all tests are passing, making this mostly a change that users won't notice, except in the special cases that previously didn't work.Fixes: #70