<s> class BasicSerializer ( object ) : <EOL> fields = ( ) <EOL> @ classmethod <EOL> def serialize ( cls , instance , fields = None ) : <EOL> data_dict = { } <EOL> use_fields = fields if fields else cls . fields <EOL> if not use_fields : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> for field in use_fields : <EOL> value = getattr ( instance , field ) <EOL> if value is None : <EOL> data_dict [ field ] = value <EOL> else : <EOL> f = getattr ( instance . __class__ , field ) <EOL> if hasattr ( f , "<STR_LIT>" ) : <EOL> rel = f . impl . __class__ . __name__ <EOL> if rel == '<STR_LIT>' : <EOL> data_dict [ field ] = value . id <EOL> elif rel == '<STR_LIT>' : <EOL> data_dict [ field ] = [ v . id for v in value ] <EOL> else : <EOL> data_dict [ field ] = value <EOL> else : <EOL> data_dict [ field ] = value <EOL> return data_dict </s>
