code: def test_encode_custom_json_encoders_model_pydanticv2():
      from pydantic import field_serializer
  
      class ModelWithCustomEncoder(BaseModel):
          dt_field: datetime
  
          @field_serializer("dt_field")
          def serialize_dt_field(self, dt):
              return dt.replace(
                  microsecond=0, tzinfo=timezone.utc
              ).isoformat()
  
      class ModelWithCustomEncoderSubclass(ModelWithCustomEncoder):
          pass
  
      model = ModelWithCustomEncoder(dt_field=datetime(2019, 1, 1, 8))
      assert jsonable_encoder(model) == {
          "dt_field": "2019-01-01T08:00:00+00:00"
      }
      subclass_model = ModelWithCustomEncoderSubclass(
          dt_field=datetime(2019, 1, 1, 8)
      )
      assert jsonable_encoder(subclass_model) == {
          "dt_field": "2019-01-01T08:00:00+00:00"
      }
  
imports: from collections import deque
  from dataclasses import dataclass
  from datetime import datetime, timezone
  from decimal import Decimal
  from enum import Enum
  from pathlib import PurePath, PurePosixPath, PureWindowsPath
  from typing import Optional
  import pytest
  from fastapi._compat import PYDANTIC_V2
  from fastapi.encoders import jsonable_encoder
  from pydantic import BaseModel, Field, ValidationError
  from .utils import needs_pydanticv1, needs_pydanticv2
label_desc: Use image node_id 6 for calling a global function with example usage: test_encode_custom_json_encoders_model_pydanticv2() and returns: dt