Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathlib support #202

Closed
illeatmyhat opened this issue Apr 2, 2020 · 2 comments
Closed

Pathlib support #202

illeatmyhat opened this issue Apr 2, 2020 · 2 comments

Comments

@illeatmyhat
Copy link

It's annoying to define this for every path. It ought to be supported natively.

@dataclass_json
@dataclass
class Foo:
    file_path: Path = field(metadata=config(encoder=str, decoder=Path))
@dalek-who
Copy link

Following #139, a possibility solution is global register Path for dataclasses_json manually:

import dataclasses_json.cfg
from pathlib import Path

dataclasses_json.cfg.global_config.encoders[Path] = str
dataclasses_json.cfg.global_config.decoders[Path] = Path  # is this necessary?

@dataclass_json
@dataclass
class Foo:
    file_path: Path

@george-zubrienko
Copy link
Collaborator

Closing as the question was answered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants