| 213 | ) |
| 214 | |
| 215 | def serialize_json( |
| 216 | self, |
| 217 | value: Any, |
| 218 | *, |
| 219 | include: IncEx | None = None, |
| 220 | exclude: IncEx | None = None, |
| 221 | by_alias: bool = True, |
| 222 | exclude_unset: bool = False, |
| 223 | exclude_defaults: bool = False, |
| 224 | exclude_none: bool = False, |
| 225 | ) -> bytes: |
| 226 | # What calls this code passes a value that already called |
| 227 | # self._type_adapter.validate_python(value) |
| 228 | # This uses Pydantic's dump_json() which serializes directly to JSON |
| 229 | # bytes in one pass (via Rust), avoiding the intermediate Python dict |
| 230 | # step of dump_python(mode="json") + json.dumps(). |
| 231 | return self._type_adapter.dump_json( |
| 232 | value, |
| 233 | include=include, |
| 234 | exclude=exclude, |
| 235 | by_alias=by_alias, |
| 236 | exclude_unset=exclude_unset, |
| 237 | exclude_defaults=exclude_defaults, |
| 238 | exclude_none=exclude_none, |
| 239 | ) |
| 240 | |
| 241 | def __hash__(self) -> int: |
| 242 | # Each ModelField is unique for our purposes, to allow making a dict from |