You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am composing a new JSONArray from String a and String b combined in a list. Then I am composing a new JSONArray from a single string which contains a and b (in a different order though)
When I do a JSONAssert on both JSONArrays it tries to compare {"a":"b"} to a JSON object.
Console output: Note the backslashes in the first print line
["{\"a\":\"b\"}","{\"c\":\"d\"}"]
[{"c":"d"},{"a":"b"}]
Exception in thread "main" java.lang.AssertionError: [0]
Expected: {"a":"b"}
got: a JSON object
; [1]
Expected: {"c":"d"}
got: a JSON object
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:726)
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:709)
at step_definitions.StepDefinitions.main(StepDefinitions.java:205)
Code to reproduce in Java:
public static void main(String[] args) throws JSONException {
var a = "{\"a\":\"b\"}";
var b = "{\"c\":\"d\"}";
var res = "[{\"c\":\"d\"},{\"a\":\"b\"}]";
final var jsonElements = new JSONArray(List.of(a,b));
final var resultJsonArray = new JSONArray(res);
System.out.println(jsonElements);
System.out.println(resultJsonArray);
JSONAssert.assertEquals(jsonElements, resultJsonArray, JSONCompareMode.STRICT);
}
The text was updated successfully, but these errors were encountered:
Build JsonObject List and then pass it.
var a = "{"a":"b"}";
var b = "{"c":"d"}";
var res = "[{"c":"d"},{"a":"b"}]";
List<JSONObject> jsonObjectList = new ArrayList<>();
jsonObjectList.add(new JSONObject(a));
jsonObjectList.add(new JSONObject(b));
final var jsonElements = new JSONArray(jsonObjectList);
final var resultJsonArray = new JSONArray(res);
System.out.println(jsonElements);
System.out.println(resultJsonArray);
JSONAssert.assertEquals(jsonElements, resultJsonArray, JSONCompareMode.NON_EXTENSIBLE);
I hope below code is self explanatory. If not:
I am composing a new JSONArray from String a and String b combined in a list. Then I am composing a new JSONArray from a single string which contains a and b (in a different order though)
When I do a JSONAssert on both JSONArrays it tries to compare {"a":"b"} to a JSON object.
Console output: Note the backslashes in the first print line
Code to reproduce in Java:
The text was updated successfully, but these errors were encountered: