Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

_NULL_TYPE not JSON serializable #177

Open
DrWacker opened this issue Jan 11, 2022 · 0 comments
Open

_NULL_TYPE not JSON serializable #177

DrWacker opened this issue Jan 11, 2022 · 0 comments

Comments

@DrWacker
Copy link

When Using the Nullable type option if the value isn't set and is therefore _NULL_TYPE json.dump will throw an error. See code example below.

>>> from dataclasses_jsonschema.type_defs import _NULL_TYPE
>>> my_dict = { "foo" : _NULL_TYPE }
>>> import json
>>> my_str = json.dumps(my_dict)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>                                                                                                                    File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode                                                                                           chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode                                                                                       return _iterencode(o, 0)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type type is not JSON serializable
>>>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant