apply fp_serialize() changes on main serialize() method

pull/1/head
Emmanuelle Vargas-Gonzalez 2021-03-18 18:08:31 -04:00
parent 922de111ed
commit c2d360d223
1 changed files with 4 additions and 10 deletions

View File

@ -2,6 +2,7 @@
import copy
import datetime as dt
import io
import simplejson as json
@ -73,16 +74,9 @@ def serialize(obj, pretty=False, include_optional_defaults=False, **kwargs):
When ``pretty=True`` the following key-value pairs will be added or
overridden: indent=4, separators=(",", ": "), item_sort_key=sort_by.
"""
if pretty:
def sort_by(element):
return find_property_index(obj, *element)
kwargs.update({'indent': 4, 'separators': (',', ': '), 'item_sort_key': sort_by})
if include_optional_defaults:
return json.dumps(obj, cls=STIXJSONIncludeOptionalDefaultsEncoder, **kwargs)
else:
return json.dumps(obj, cls=STIXJSONEncoder, **kwargs)
with io.StringIO() as fp:
fp_serialize(obj, fp, pretty, include_optional_defaults, **kwargs)
return fp.getvalue()
def fp_serialize(obj, fp, pretty=False, include_optional_defaults=False, **kwargs):