Skip to content

Commit ef6f466

Browse files
committed
Fixed MapData export serialization methods
1 parent 122b3b2 commit ef6f466

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

highcharts_maps/options/series/data/map_data.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,48 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
249249

250250
return untrimmed
251251

252+
@staticmethod
253+
def trim_dict(untrimmed: dict,
254+
to_json: bool = False,
255+
context: str = None,
256+
for_export: bool = False) -> dict:
257+
"""Remove keys from ``untrimmed`` whose values are :obj:`None <python:None>` and
258+
convert values that have ``.to_dict()`` methods.
259+
260+
:param untrimmed: The :class:`dict <python:dict>` whose values may still be
261+
:obj:`None <python:None>` or Python objects.
262+
:type untrimmed: :class:`dict <python:dict>`
263+
264+
:param to_json: If ``True``, will remove all keys from ``untrimmed`` that are not
265+
serializable to JSON. Defaults to ``False``.
266+
:type to_json: :class:`bool <python:bool>`
267+
268+
:param context: If provided, will inform the method of the context in which it is
269+
being run which may inform special handling cases (e.g. where empty strings may
270+
be important / allowable). Defaults to :obj:`None <python:None>`.
271+
:type context: :class:`str <python:str>` or :obj:`None <python:None>`
272+
273+
:param for_export: If ``True``, indicates that the method is being run to
274+
produce a JSON for consumption by the export server. Defaults to ``False``.
275+
:type for_export: :class:`bool <python:bool>`
276+
277+
:returns: Trimmed :class:`dict <python:dict>`
278+
:rtype: :class:`dict <python:dict>`
279+
"""
280+
if not for_export:
281+
return HighchartsMeta.trim_dict(untrimmed = untrimmed,
282+
to_json = to_json,
283+
context = context,
284+
for_export = for_export)
285+
286+
topology = untrimmed.get('topology', None)
287+
288+
return topology
289+
252290
def to_json(self,
253291
filename = None,
254-
encoding = 'utf-8'):
292+
encoding = 'utf-8',
293+
for_export: bool = False):
255294
"""Generate a JSON string/byte string representation of the object compatible with
256295
the Highcharts JavaScript library.
257296
@@ -271,6 +310,10 @@ def to_json(self,
271310
to ``'utf-8'``.
272311
:type encoding: :class:`str <python:str>`
273312
313+
:param for_export: If ``True``, indicates that the method is being run to
314+
produce a JSON for consumption by the export server. Defaults to ``False``.
315+
:type for_export: :class:`bool <python:bool>`
316+
274317
:returns: A JSON representation of the object compatible with the Highcharts
275318
library.
276319
:rtype: :class:`str <python:str>` or :class:`bytes <python:bytes>`

0 commit comments

Comments
 (0)