Git Product home page Git Product logo

Comments (2)

ramonhagenaars avatar ramonhagenaars commented on July 18, 2024

Hi @yurirocha15 ,

You are trying to load a "half json-serialized" object; a dict that contains objects that are not json-compatible (bson.objectid.ObjectId instances).

I traced down what happened. In non-strict mode, when an object is loaded into a class of which it already is an instance (e.g. load("this is a string", str)), the loading is skipped and that instance is returned instantly. This is what happens with your data1. With data2, it compares the type ObjectId with Optional which are inequal, therefore it is not skipped. Then, before actually trying to deserialize an ObjectId, it stops as ObjectId is not a json value (one of str, int, float, bool, list, tuple, set, dict, NoneType).

Do you really need to load a "half json-serialized" object, or would it be possible in your case to just do the following?

TestData(**data2)

from jsons.

yurirocha15 avatar yurirocha15 commented on July 18, 2024

This would be possible in the example I posted but not in my real use case. I am parsing a nested dictionary into nested dataclasses; this optional parameter is in the deeper layers of the dictionary. Therefore, using the root dataclass constructor directly is not an option for me.

Is there any way to solve this using custom serializers/deserializers?

from jsons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.