gson进行序列化时,会发生内存溢出的情况,一种情况是因为:在序列化对象中有logger对象。
这时需要设置logger的属性
private transient final static Logger logger = LoggerFactory.getLogger(UnicomMobileBillInfoTemplate.class);
需要加上transient 属性。
在stackoverflow上看到的一句话:
The transient keyword on a variable will ensure that the variable is not part of the serialized object when serializing.
If your class is not serializable, nor a JPA entity (which uses the transient keyword to avoid storing variables in the database), removing it should be fine.
网友评论