tasktiger icon indicating copy to clipboard operation
tasktiger copied to clipboard

Set json encoder/decoder via config

Open xuru opened this issue 8 years ago • 2 comments

Allows for custom serialization/deserialization and defaults to the built json encoder/decoder. This also sets the encoder/decoder for all places json.dump(s) and json.load(s) is used (i.e. gen_unique_id).

This allows you to use a custom encoder/decoder and still use unique=True on tasks.

TODO: add tests, and docs

xuru avatar Dec 30 '17 01:12 xuru

Thanks! Any downside on doing it the way https://github.com/closeio/tasktiger/pull/92 or https://github.com/closeio/tasktiger/pull/22 do it? Those give additional flexibility since they allow for encoders/decoders other than JSON.

thomasst avatar Jan 04 '18 19:01 thomasst

No downside, but I'm using flask/jinja2 and I just use the same encoder/decoder here.

One thing we could do, is specify the serialization method, and the encoder/decoders that go with it. So, something like:

self.config = {
    'SERIALIZATION_METHOD': 'json',
    'SERIALIZATION_ENCODER': JSONEncoder,
    'SERIALIZATION_DECODER': JSONDecoder,

which would open the door to something like using yaml, or pickle.

I can add this if you like this weekend.

xuru avatar Jan 05 '18 18:01 xuru