Skip to content

Commit

Permalink
fix pretty format
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 30, 2024
1 parent c51f917 commit 8ef8ce4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion core/src/main/java/com/alibaba/fastjson2/JSONWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,6 @@ public void write(JSONObject map) {
}

final long NONE_DIRECT_FEATURES = ReferenceDetection.mask
| PrettyFormat.mask
| NotWriteEmptyArray.mask
| NotWriteDefaultValue.mask;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public static class Bean3 {
public void ofPretty() {
JSONWriter jsonWriter = JSONWriter.of();
jsonWriter = JSONWriter.ofPretty(jsonWriter);
jsonWriter = JSONWriter.ofPretty(jsonWriter);
jsonWriter.startObject();
jsonWriter.writeNameValue("id", 123);
jsonWriter.endObject();
Expand Down Expand Up @@ -236,15 +237,17 @@ public void testJSONObject() {
"f4", new JSONObject(),
"f5", new JSONArray()
);
JSONWriter jsonWriter = JSONWriter.of(PrettyFormat);
jsonWriter.write(object);
assertEquals("{\n" +
"\t\"f1\":101,\n" +
"\t\"f2\":102,\n" +
"\t\"f3\":103,\n" +
"\t\"f4\":{},\n" +
"\t\"f5\":[]\n" +
"}", jsonWriter.toString());
{
JSONWriter jsonWriter = JSONWriter.of(PrettyFormat);
jsonWriter.write(object);
assertEquals("{\n" +
"\t\"f1\":101,\n" +
"\t\"f2\":102,\n" +
"\t\"f3\":103,\n" +
"\t\"f4\":{},\n" +
"\t\"f5\":[]\n" +
"}", jsonWriter.toString());
}
}
{
JSONWriter jsonWriter = JSONWriter.of(PrettyFormat);
Expand Down

0 comments on commit 8ef8ce4

Please sign in to comment.