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.