question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Use of dotmap or equivalent to simplify usage of the deserialized object

See original GitHub issue

Because Marshmallow provides a nice abstraction over the datamodel, it might be nice to go even further and use something like DotMap (https://github.com/drgrib/dotmap) to simplify using the objects.

E.g. instead of

user['created_at']

you could type:

user.created_at

This also provides the benefit of giving you a layer to prevent messing with the object (instead of with a visible dict data structure, where it feels like it’s more open to interference).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, Apr 7, 2020

Yes, a post_load method is a good place to do this. If you want to use DotMap as the dict class for both deserialization and serialization, you can override dict_class, like so:

from dotmap import DotMap
from marshmallow import Schema, fields


class MySchema(Schema):
    dict_class = DotMap

    foo = fields.Str()


schema = MySchema()
loaded = schema.load({"foo": "bar"})
print(loaded)
# DotMap(foo='bar')
dumped = schema.dump(loaded)
print(dumped)
# DotMap(foo='bar')
0reactions
deckar01commented, Apr 8, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

https://techdocs.broadcom.com/content/dam/broadcom...
Other entities like the creator of the item may * be added in the corresponding field. Notes on usage rights should be *...
Read more >
2021年01月_weixin_39765100的博客_CSDN博客
2021-01-12. Visual indication of modal status. 2021-01-12. Proposal: Use of dotmap or equivalent to simplify usage of the deserialized object. 2021-01-12 ...
Read more >
openthings的个人空间- OSCHINA - 中文开源技术交流社区
This is basically a POST that attaches an object which describes the target node. 为了调度Pod在随机的节点上,我们创建一个Binding 对象。将POST 关联到描述目标节点 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found