-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pretty errors when deserializing objects #206
Comments
yep, this would be useful -- i think this is a good opportunity to take a stab at an initial error hierarchy (deserialization, serialization, etc.), as |
I'm not sure how this library works internally. But I'd just like to add that, not only from typing import Optional
from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
@dataclass
class MyModel(DataClassJsonMixin):
required_value: str
optional_value: Optional[str] = None
MyModel.from_json('{}') # KeyError
MyModel.schema().loads('{}') # KeyError I would expect that
I wanted to mention this because I see you speaking of error hierarchies. My first thought was: "what hierarchy? I just want the |
This is really something you'd expect the library to do out of box. |
Target of v1 API #442 - take a look. |
It would be nice if a "pretty" exception was raised when a particular json cannot be mapped to a @dataclass-json object, instead of raising
KeyError
exceptions.Right now if the json string cannot be mapped a KeyError exception is raised, saying that a particular field isn't available, but this field might be from a child of a child of the root object and it might be hard to determine which field it's taking about just by the name
The text was updated successfully, but these errors were encountered: