I'm sometimes getting this error when serialising an object
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)
With this String sessionJson = serializer.exclude("*.class").deepSerialize(response);
Can anyone tell me what ConcurrentModificationException
is all about?
Possible that same instance of JSONSerializer is shared between two threads and along with serialize, there are other calls/invocations. Check the calls to includes/excludes, use, transforms etc., which should be before the first thread invokes serialize.
Other option is to use CopyOnWriteArrayList, such as :
serializer = new flexjson.JSONSerializer();
List pathExpressions = (List)BeanUtil.getDeclaredProperty(serializer, "pathExpressions");
pathExpressions = new CopyOnWriteArrayList(pathExpressions);
BeanUtil.setDeclaredProperty(serializer, "pathExpressions", pathExpressions);