Giter Site home page Giter Site logo

Comments (4)

ahmetkucuk avatar ahmetkucuk commented on June 16, 2024 2

Not tried but I would expect following code to work.

f1 = jsons.JsonSerializable.fork()
f1.set_serializer(my_datetime_serializer, datetime)
jsons.dump(foo, fork_inst=f1)

I did not see it in the documentation. Maybe the documentation could be updated.

from jsons.

ahmetkucuk avatar ahmetkucuk commented on June 16, 2024 1

I did not have a chance to look in detail. In general, it makes sense to me directly calling jsons.fork()

Is there any way of avoiding .copy() in the .fork()?

Instead, maybe we can use a fallback approach: if there is a serializer/deserializer is defined in custom JsonSerializable, use it. Otherwise, use globally defined one?

I think Gson library uses a builder where you can also pass configurations:
https://static.javadoc.io/com.google.code.gson/gson/2.8.2/com/google/gson/GsonBuilder.html

In jsons, some configurations cannot be defined in JsonSerializable I guess? e.g. key_transformer

from jsons.

casparjespersen avatar casparjespersen commented on June 16, 2024

Thank you @ahmetkucuk. That works.

from jsons.

ramonhagenaars avatar ramonhagenaars commented on June 16, 2024

Great question Casparjespersen. Even though @ahmetkucuk answered your question correctly, I believe your suggestion deserves consideration. I like the idea of being able to "temporarily" override the (de)serialization behavior of some types.

As for the current solution that Ahmetkucuk rightly mentioned, I'm thinking of deprecating it (to have it removed later). It makes no sense (anymore) that JsonSerializable is to be involved. Rather, I'm thinking of a mere function like jsons.fork().

I am curious about the opinion of you guys on this. 🙂

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.