Skip to content

Commit

Permalink
fix browserCompatible issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielHwang authored and wenshao committed Aug 15, 2023
1 parent 476216d commit 3b55881
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ public final void writeListInt64(List<Long> values) {

long v = item.longValue();
boolean writeAsString = nonStringAsString
|| (browserCompatible && v <= 9007199254740991L && v >= -9007199254740991L);
|| (browserCompatible && !(v <= 9007199254740991L && v >= -9007199254740991L));
if (writeAsString) {
chars[off++] = this.quote;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.alibaba.fastjson2.issues_1700;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1742 {
@Getter
public static class TestFastJson {
private long a = 1443605444282772302L;
private List<Long> b = new ArrayList<Long>() {{
add(1443605444282772302L);
add(1443605444282772303L);
add(1L);
}};
}
@Test
public void test() {
TestFastJson testFastJson = new TestFastJson();
String jsonString = JSON.toJSONString(testFastJson,JSONWriter.Feature.BrowserCompatible);
assertEquals("{\"a\":\"1443605444282772302\",\"b\":[\"1443605444282772302\",\"1443605444282772303\",1]}", jsonString);
}
}

0 comments on commit 3b55881

Please sign in to comment.