Interface for classes that wish to control their own serialization.
Called during serialization to JSON.