0

Getting exception with the following code: org.glassfish.json.JsonStringImpl cannot be cast to javax.json.JsonArray

JsonObjectParser jop = new JsonObjectParser();
JsonObject jo = Json.createObjectBuilder().add("yAxisValue","Yvalue")
            .add("xAxisValue","Xvalue").build();
jo.getJsonArray("xAxisValue");

Note: using javax.json java API

2 Answers 2

1

For creating JSON Array by javax.json use following method.

JsonArray value = Json.createArrayBuilder()
     .add(Json.createObjectBuilder()
         .add("type", "home")
         .add("number", "212 555-1234"))
     .add(Json.createObjectBuilder()
         .add("type", "fax")
         .add("number", "646 555-4567"))
     .build();
Sign up to request clarification or add additional context in comments.

Comments

1

The error is the following

.add("xAxisValue","Xvalue")

the statement above is not to create a json array, the json string you created is the following

{ 
  "yAxisValue":"Yvalue",
  "xAxisValue":"Xvalue"
}

not

{ 
  "yAxisValue":"Yvalue",
  "xAxisValue":["Xvalue"]
}

you should use the function add("key",Json.createArrayBuilder(...))

hope that helped

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.