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

Prevent conversion of string properties to JSONArrays or JSONObjects … #45

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/sf/json/JSONSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public static JSON toJSON( Object object, JsonConfig jsonConfig ) {
json = toJSON( (String) object, jsonConfig );
}else if( JSONUtils.isArray( object ) ){
json = JSONArray.fromObject( object, jsonConfig );
}else if( object instanceof JSONObject){
json = (JSONObject)object;
}else{
try{
json = JSONObject.fromObject( object, jsonConfig );
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/sf/json/TestJSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ public void testElement_Object() {
jsonObject.getJSONObject( "bean" ) );
}

public void testElement_Object_nested() {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.element( "str", "\"[]\"" );
Assertions.assertTrue(jsonObject1.get( "str" ) instanceof String);

JSONObject jsonObject2 = new JSONObject();
jsonObject2.element( "obj", jsonObject1);
Assertions.assertTrue(jsonObject2.getJSONObject( "obj" ).get( "str" ) instanceof String);
}

public void testElement_String() {
JSONObject jsonObject = new JSONObject();
jsonObject.element( "str", "json" );
Expand Down