question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map deserialization inside objects

See original GitHub issue

As mentioned in gitter:

Exception raised when trying to pass in a Map via a mutation:

mutation isoCountryUpdate {
  isoCountryUpdate(input: {
    clientMutationId: "1234"
      isoCountry: {
          id: 2747
          codeAlpha2: "YY"
          codeAlpha3: "YYY"
          name: "TEST"
          codeNumeric: "66"
          confirmationResponses: {key: "TEST", value: "NO"}
      }
    }) {
    clientMutationId
    result {
      id
      name
    }
  }
}
Caused by: java.lang.IllegalArgumentException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token
 at [Source: N/A; line: -1, column: -1] (through reference chain: p4.entities.common.IsoCountry["confirmationResponses"])
    at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3605) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3546) ~[jackson-databind-2.8.9.jar:2.8.9]
    at io.leangen.graphql.metadata.strategy.value.jackson.JacksonValueMapper.fromInput(JacksonValueMapper.java:33) ~[spqr-0.9.3.jar:na]
    at io.leangen.graphql.metadata.strategy.value.ValueMapper.fromInput(ValueMapper.java:11) ~[spqr-0.9.3.jar:na]
    at io.leangen.graphql.generator.mapping.common.InputValueDeserializer.getArgumentValue(InputValueDeserializer.java:19) ~[spqr-0.9.3.jar:na]
    at io.leangen.graphql.execution.ResolutionEnvironment.getInputValue(ResolutionEnvironment.java:63) ~[spqr-0.9.3.jar:na]
    at io.leangen.graphql.execution.OperationExecutor.execute(OperationExecutor.java:91) ~[spqr-0.9.3.jar:na]
    at io.leangen.graphql.execution.OperationExecutor.execute(OperationExecutor.java:59) ~[spqr-0.9.3.jar:na]
    ... 129 common frames omitted
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token
 at [Source: N/A; line: -1, column: -1] (through reference chain: p4.entities.common.IsoCountry["confirmationResponses"])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1122) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1075) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:892) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:358) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:27) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:504) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:104) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) ~[jackson-databind-2.8.9.jar:2.8.9]
    at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3600) ~[jackson-databind-2.8.9.jar:2.8.9]
    ... 136 common frames omitted

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcoopercommented, Oct 16, 2017

I believe we had the same issue and fixed it by setting: generator.withScalarMappingStrategy(new MapScalarStrategy());

0reactions
kvzncommented, Jan 14, 2019

I solved the this JSON parse issue by replacing “Map<String, String> request” with “Map<String, Object> request”

@PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Map<String, Object> graphql(@RequestBody Map<String, Object> request, HttpServletRequest raw) {
        ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput()
                .query(request.get("query").toString())
                .operationName(request.get("operationName") != null ? request.get("operationName").toString() : null)
                .context(raw)
                .build());
        return executionResult.toSpecification();
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Map Serialization and Deserialization with Jackson - Baeldung
A quick and practical guide to serializing and deserializing Java Maps using Jackson.
Read more >
Deserializing into a HashMap of custom objects with jackson
You should create specific Map type and provide it into deserialization process: TypeFactory typeFactory = mapper.
Read more >
Map Serialization and Deserialization with Jackson
A process of converting the stream of bytes into a Java object is referred to as deserialization. We can deserialize the JSON data...
Read more >
MapDeserializer (jackson-databind 2.8.6 API) - javadoc.io
Basic serializer that can take JSON "Object" structure and construct a Map instance, with typed contents. Note: for untyped content (one indicated by ......
Read more >
Jackson - List, Set and Map Serialization and Deserialization ...
In this article, I show you how to use the Jackson API to serialize and deserialize the java collection objects such as List,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found