I was getting a serialization exception when I tried to serialize a JFreeChart chart to a file. The error message and corresponding stacktrace offered little in the way of clues. I finally figured out that the problem was with an interface implementation I had set for generating custom legend item labels. I used a lambda expression to supply the interface (
XYSeriesLabelGenerator) implementation. Alternatively, one might use an anonymous inner class to provide the implementation. Neither of these approaches will work, as it is not possible (as far as I know) to implement the Serializable interface for the implementation. So, I used the good, old, named top-level class:
XYItemRenderer renderer = ...; renderer.setLegendItemLabelGenerator( new CustomSeriesLabelGenerator());
So, if you are getting an error when serializing a JFreeChart chart, check how you have passed any interface implementations into a setter… that may be the problem.