Implement #serialize and #toJSON