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.

[Ljava.lang.Object; error when using JSON arrays

See original GitHub issue

I’m trying to send an array of elements as an argument (e.g. [String!]!) but I keep getting the following error: Variable '$temp' expected value of type '[String!]!' but got: [Ljava.lang.Object;@1232fa01. Reason: [at index #0] String value expected

This happens for any type (String, Int, Boolean, etc.) that attempts to use an array.

I’ve over simplified my setup to test this issue and even this very basic example doesn’t work for me (it’s missing a couple of pieces for simplicity, don’t worry about them… this works when not using an array):

val tempArg = Argument("temp", ListInputType(StringType))

val queryFields: List[Field[SangriaCtx, Unit]] = fields(
    Field("temp", OptionType(SomeObjectType),
      description = Some("Returns some object"),
      arguments = tempArg :: Nil,
      resolve = c => {
        // do anything that returns SomeObjectType..
      })

Query:

query temp($temp: [String!]!) {
  temp(temp: $temp) {
    name
  }
}

{
  "temp": [] // or ["word"], for example
}

Strangely (?) sending a string will cast it to a Vector with length of 1…

Please let me know if I’m doing something wrong… Thanks, Elad

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
elad-sterncommented, Jul 19, 2017

OK, so this has been an incredibly specific issue that probably wouldn’t concern most people but it was eventually resolved. The root cause was indeed Finatra server. Finatra uses Jackson for JSON parsing and they encountered a performance issue you can read about here. They resolved it by opting to work with java objects instead of scala ones, but allowed an optional flag DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY to be turned off in case it causes any issues - which it did for us.

Anyway, long story short, we deactivated this feature and everything now works as expected. Thanks!

1reaction
OlegIlyenkocommented, Jul 13, 2017

Alternatively, you can also write a custom InputUnmarshaller for this finatra-specific JSON format represented with Map[String, Any]. Though my first suggestion is probably a bit simpler to implement and use

Read more comments on GitHub >

github_iconTop Results From Across the Web

kotlin - java.lang.IllegalStateException:JSON OBJECT and ...
JSON data convert through gson. Gives Error: "java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path ...
Read more >
Jackson JSON Java Parser API Example Tutorial - DigitalOcean
For our example for JSON to POJO/Java object conversion, we will take a complex example with nested object and arrays. We will use...
Read more >
Parsing JSON Arrays as Objects with Jackson - Level Up Coding
In this article, I'll describe a trick from the Jackson JSON parsing library that allows parsing non-typical JSON with greater flexibility.
Read more >
JSONArray
A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the...
Read more >
com.ibm.json.java.JSONObject incompatible with com.ibm ...
JSONArray when updating properties with the saveAttributes() method ... As the error describes, it should be Json array not Json object. You can...
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