Skip to content

Commit

Permalink
Fix JSON serialization
Browse files Browse the repository at this point in the history
Extended the default_encoder function to handle Path objects by converting them to their string representation. This ensures that Path objects can be properly serialized to JSON format.
  • Loading branch information
coordt committed Aug 8, 2024
1 parent 84c885a commit d3f3022
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bumpversion/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
from io import StringIO
from pathlib import Path
from pprint import pprint
from typing import Any, Optional

Expand Down Expand Up @@ -39,6 +40,8 @@ def default_encoder(obj: Any) -> str:
return str(obj)
elif isinstance(obj, type):
return obj.__name__
elif isinstance(obj, Path):
return str(obj)

Check warning on line 44 in bumpversion/show.py

View check run for this annotation

Codecov / codecov/patch

bumpversion/show.py#L44

Added line #L44 was not covered by tests
raise TypeError(f"Object of type {type(obj), str(obj)} is not JSON serializable")

print_info(json.dumps(value, sort_keys=True, indent=2, default=default_encoder))
Expand Down

0 comments on commit d3f3022

Please sign in to comment.