Skip to content

#177 Avoid explicitly inject ObjectMapper to the ObjectMapper #178

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public ObjectMapper provide() {
SerializationFeature.FAIL_ON_EMPTY_BEANS).registerModule(new Jdk8Module());
objectMapperConfigurer.configure(mapper);

InjectableValues.Std injectableValues = new InjectableValues.Std();
injectableValues.addValue(ObjectMapper.class, mapper);
mapper.setInjectableValues(injectableValues);

return mapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package graphql.servlet.internal;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Map;
Expand All @@ -15,17 +15,17 @@
public class VariablesDeserializer extends JsonDeserializer<Map<String, Object>> {
@Override
public Map<String, Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return deserializeVariablesObject(p.readValueAs(Object.class), (ObjectMapper) ctxt.findInjectableValue(ObjectMapper.class.getName(), null, null));
return deserializeVariablesObject(p.readValueAs(Object.class), p.getCodec());
}

public static Map<String, Object> deserializeVariablesObject(Object variables, ObjectMapper mapper) {
public static Map<String, Object> deserializeVariablesObject(Object variables, ObjectCodec codec) {
if (variables instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> genericVariables = (Map<String, Object>) variables;
return genericVariables;
} else if (variables instanceof String) {
try {
return mapper.readValue((String) variables, new TypeReference<Map<String, Object>>() {});
return codec.readValue(codec.getFactory().createParser((String) variables), new TypeReference<Map<String, Object>>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down