Search code examples
javadeserializationpath-2d

How do I desserialize a Path2D.Double object?


I'm trying to save an object that has an ArrayList of Connector, which is a class that extends Path2D.Double. It gives me the exception gui.Connector; no valid constructor. I did a little research and came across this:

no valid constructor when serializing a subclass of Path2D.Double

It gave me a fine explanation, but no workaround. Is there a way I can desserialize a subclass of Path2D.Double?


Solution

  • The Path2D.Double can be serialized/deserialized without issue (it has access to the Path2D no-arg constructor). If you do not need to override the behavior of Path2D.Double, you can have an instance of this class as a field in your Connector class (rather than have Connector extend the Path2D.Double).