samples-python
samples-python copied to clipboard
Sample request: Pydantic v2 converter
Describe the solution you'd like
Rename sample pydantic_converter to pydanticv1_converter (and tests/packages/dep-group/etc) and make a new pydantic_converter sample that works with v2
I am setting up a new project and I would really appreciate this for the "type safety without having to redefine attributes twice" benefits!
In particular, the pydantic_encoder does not work anymore in v2: https://github.com/pydantic/pydantic/discussions/6652
Until the sample is present, you can apply the concepts/approaches of the custom conversion to whatever is needed for v2 without applying the specific code
@JaneJeon I am using pydantic 2 with temporal just by changing pydantic_encoder to to_jsonable_python:
from pydantic_core import to_jsonable_python
...
# We let JSON conversion errors be thrown to caller
return Payload(
metadata={"encoding": self.encoding.encode()},
data=json.dumps(value, separators=(",", ":"), sort_keys=True, default=to_jsonable_python).encode(),
)