String GLEO = JSON.toJSONString(GLEOArray);
String PLEO = PLEOArray.toString();
String ILEO = ILEOArray.toString();
String fac = facArray.toString();
String terminal = terminalArray.toString();
最近需要处理一部分的czml文件,上面的代码就是在将处理好的JSONArray对象转换为字符串方便存储但是会在转换过程中爆错内存溢出
Exception in thread "main" java.lang.OutOfMemoryError
at com.alibaba.fastjson2.JSONWriterUTF16.ensureCapacity(JSONWriterUTF16.java:1564)
at com.alibaba.fastjson2.JSONWriterUTF16.writeDecimal(JSONWriterUTF16.java:1289)
at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:314)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548)
at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:366)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2756)
at org.example.Main.main(Main.java:404)
经过排查发现是FastJson2的tostring默认情况下单对象最大支持64M 所以需要使用到Feature来配置序列化
// 将 JSON 数组转换为字符串
String GLEO = JSON.toJSONString(GLEOArray, JSONWriter.Feature.LargeObject);
String PLEO = JSON.toJSONString(PLEOArray, JSONWriter.Feature.LargeObject);
String ILEO = JSON.toJSONString(ILEOArray, JSONWriter.Feature.LargeObject);
String fac = JSON.toJSONString(facArray, JSONWriter.Feature.LargeObject);
String terminal = JSON.toJSONString(terminalArray, JSONWriter.Feature.LargeObject);