fastjson2序列化报错OutOfMemoryError

报错log如下,这里用的是阿里的com.alibaba.fastjson2 2.0.9版本,该版限制了最大可以序列化大小是64M,超过了就报错OutOfMemoryError

Exception in thread "pool-4-thread-1" java.lang.OutOfMemoryError
	at com.alibaba.fastjson2.JSONWriterUTF16.writeNameRaw(JSONWriterUTF16.java:561)
	at com.alibaba.fastjson2.writer.FieldWriterImpl.writeFieldName(FieldWriterImpl.java:143)
	at com.alibaba.fastjson2.writer.ObjectWriter_3.write(Unknown Source)
	at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:278)
	at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:1757)
	at com.liness.common.redis.configure.FastJson2JsonRedisSerializer.serialize(FastJson2JsonRedisSerializer.java:35)
	at org.springframework.data.redis.core.AbstractOperations.rawValue(AbstractOperations.java:128)
	at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:323)
	at com.liness.common.redis.service.RedisService.setCacheObject(RedisService.java:71)
	at com.liness.business.web.controller.tools.DownLoadFileToolsController.lambda$exportPayDetail$2(DownLoadFileToolsController.java:184)
	at com.alibaba.ttl.TtlRunnable.run(TtlRunnable.java:59)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

解决办法

升级到2.0.16

报错的代码:

String jsonString2 = JSON.toJSONString(decodeJson);

正确代码:加上 JSONWriter.Feature.LargeObject

String jsonString2 = JSON.toJSONString(decodeJson, JSONWriter.Feature.LargeObject);

你可能感兴趣的:(大数据,大数据)