0

序列化对象时有时会出现此错误

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

4

1 回答 1

1

JSONSerializer 的同一个实例可能在两个线程之间共享,并且与序列化一起,还有其他调用/调用。检查对包含/排除、使用、转换等的调用,这应该在第一个线程调用序列化之前。

其他选项是使用CopyOnWriteArrayList,例如:

serializer = new flexjson.JSONSerializer();
List pathExpressions = (List)BeanUtil.getDeclaredProperty(serializer, "pathExpressions");
pathExpressions = new CopyOnWriteArrayList(pathExpressions);
BeanUtil.setDeclaredProperty(serializer, "pathExpressions", pathExpressions);
于 2019-06-05T09:09:23.910 回答