[Ljava.lang.Object; error when using JSON arrays
See original GitHub issueI’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:
- Created 6 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
Alternatively, you can also write a custom
InputUnmarshaller
for this finatra-specific JSON format represented withMap[String, Any]
. Though my first suggestion is probably a bit simpler to implement and use