我有一个简单的例子:
from dataclasses import dataclass
import marshmallow_dataclass
@dataclass
class Tst:
fld: str
if __name__ == "__main__":
objct = marshmallow_dataclass.class_schema(Tst)().load("{\"fld\":\"value\"}")
我希望这能从JSON反序列化对象,但是结果是以下回溯:
Original exception was:
Traceback (most recent call last):
File "./main.py", line 13, in <module>
objct = marshmallow_dataclass.class_schema(Tst)().load("\"fld\":\"value\"")
File "/home/krjoff/.local/lib/python3.7/site-packages/marshmallow/schema.py", line 720, in load
data, many=many, partial=partial, unknown=unknown, postprocess=True
File "/home/krjoff/.local/lib/python3.7/site-packages/marshmallow/schema.py", line 898, in _do_load
raise exc
marshmallow.exceptions.ValidationError: {'_schema': ['Invalid input type.']}
有人可以建议如何解决此问题吗?