Move to_dict to JSONEncoder.