Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings that are also valid JSON arrays/objects are deserialized incorrectly #44

Open
tofay opened this issue Oct 3, 2017 · 0 comments

Comments

@tofay
Copy link

tofay commented Oct 3, 2017

This occurs when the string is nested and more than one level deep, e.g it occurs for
{"a": {"b": "[c-d]"}} but not {"b": "[c-d]"}

I'd expect the string "{"a": {"b": "[c-d]"}}" to be deserialized to:
{
"a" : {
"b" : "[c-d]"
}
}

It's actually deserialized to:
{
"a" : {
"b" : ["c-d"]
}
}

Here's a test for this that currently fails:

   public void testElement_Object_nested() {
      JSONObject jsonObject1 = new JSONObject();
      jsonObject1.element( "str", "\"[]\"" );
      Assertions.assertTrue(jsonObject1.get( "str" ) instanceof String); // This assertion passes
      
      JSONObject jsonObject2 = new JSONObject();
      jsonObject2.element( "obj", jsonObject1);
      Assertions.assertTrue(jsonObject2.getJSONObject( "obj" ).get( "str" ) instanceof String); // This assertion fails
   }

I'm running version 2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant