-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
JSONObject(2); #356
Comments
Please provide a complete example. Also, in the 'should be' section, use markdown styling to retain your preferred spacing (use 3 grave accent AKA backtick ` chars in a row, before and after your output) |
Do you have any example? I worked on this all day?
Thanks
Robin
…On Fri, Jul 14, 2017 at 11:40 PM, Sean Leary ***@***.***> wrote:
Please provide a complete example. Also, in the 'should be' section, use
markdown styling to retain your preferred spacing (use 3 grave accent AKA
backtick ` chars in a row, before and after your output)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#356 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGNxIRGh01-OnBYMuNEiTWUjzx6W7Ekmks5sODS7gaJpZM4OY5ZW>
.
|
```java public static final void someFunction(){ // do something } ``` generates public static final void someFunction(){
// do something
} ```json { "int": 0, "string": "string", "bool": false } ``` generates {
"int": 0,
"string": "string",
"bool": false
} |
@stleary Here is a test case: JSONObject jo = new JSONObject().put("TABLE", new JSONObject().put("yhoo", new JSONObject()));
assertEquals("toString(2)","{\n" +
" \"TABLE\": {\n" +
" \"yhoo\": {\n" +
" }\n" +
" }\n" +
"}", jo.toString(2)); and it currently fails like so:
The JUNIT error logging is making it look weird though. It's miss aligning it's surrounding brackets. I believe that @RMelanson was expecting output like this: {
"TABLE": {
"yhoo": {
}
}
} however, in https://github.com/stleary/JSON-java/blob/master/JSONObject.java#L2260 we have a check for a single element in an object. If it's a single key object, no indenting happens The following test passes on current master: JSONObject jo = new JSONObject().put("TABLE", new JSONObject().put("yhoo", new JSONObject()));
assertEquals("toString(2)","{\"TABLE\": {\"yhoo\": {}}}", jo.toString(2)); |
@RMelanson If you read my last comment on GitHub directly (I edited it a lot which doesn't go through emails) you'll see that this looks like expected behavior. When a JSONArray or JSONObject has only one element or key, then the indentation does not take effect. @stleary I don't mind changing this, but I think updating the |
@johnjaylward thanks for doing the analysis. Agree this is a case of works-as-designed, not an error. Javadoc update would be a reasonable way to address the issue. |
@RMelanson thanks for making the issue known. No objection if someone wants to create a pull request to document the behavior. |
Update test for issue stleary/JSON-java#356
Update javadoc according to issue #356.
JSONObject(2) does not indent for example:
System.out.println("jsonObject.toString(2) = \n"+jsonObject.toString(2));
Prints Out:
{"TABLE":{"yhoo":{}}}
Should be:
{
"TABLE":{
"yhoo":{
}
}
}
The text was updated successfully, but these errors were encountered: