Giter Site home page Giter Site logo

Comments (4)

ElmoVanKielmo avatar ElmoVanKielmo commented on September 21, 2024

Of course I meant to_json() and not to_dict() in description of my second commit ;)

from dataclasses-json.

lidatong avatar lidatong commented on September 21, 2024

Thanks for raising the issue and the corresponding PR!

I've given this some thought and I actually don't agree that {"bar": 7.45} should be a valid json representation of the Foo class in your example.

When considering the distinction between:
{"bar": 7.45}
vs.
{"bar": 7.45, "baz": None}

The main problem I see with making the former the json representation of a Foo is it would lead to equivalent json representations of two structurally dissimilar types:

class Foo:
    bar: float

class Foo:
    bar: float
    baz: Optional[float]

# these two classes end up having the same json repr

However, I'm in favor of adding an option to from_json to "infer missing keys as none" (which would be similar to your pr). Technically, this violates a (potential) invariant that from_json and to_json are inverses, which as nice that may be to provide, supplementing the API to support this usecase seems the more practical approach.

from dataclasses-json.

ElmoVanKielmo avatar ElmoVanKielmo commented on September 21, 2024

I completely agree.

from dataclasses-json.

lidatong avatar lidatong commented on September 21, 2024

really sorry for the long delay. infer_missing feature provided as a kwarg to from_json in https://github.com/lidatong/dataclasses-json/releases/tag/v0.0.7 along with fixes to make this lib work in 3.7

from dataclasses-json.

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.