序列化对象时有时会出现此错误
flexjson.JSONException: Error trying to deepSerialize
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:61)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:49)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.JSONContext.transform(JSONContext.java:73)
at flexjson.JSONSerializer.serialize(JSONSerializer.java:377)
at flexjson.JSONSerializer.deepSerialize(JSONSerializer.java:301
...
Caused by: java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1042)
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:996)
at flexjson.JSONContext.matches(JSONContext.java:434)
有了这个String sessionJson = serializer.exclude("*.class").deepSerialize(response);
谁能告诉我ConcurrentModificationException
的全部含义?
答案 0 :(得分:1)
可能在两个线程之间共享JSONSerializer的同一实例,并且随着序列化,还有其他调用/调用。在第一个线程调用序列化之前,应检查对包含/排除,使用,转换等的调用。
其他选项是使用 CopyOnWriteArrayList ,例如:
serializer = new flexjson.JSONSerializer();
List pathExpressions = (List)BeanUtil.getDeclaredProperty(serializer, "pathExpressions");
pathExpressions = new CopyOnWriteArrayList(pathExpressions);
BeanUtil.setDeclaredProperty(serializer, "pathExpressions", pathExpressions);