Add compatibility with Pydantic v2
Updated all Pydantic model classes to be compatible with both pydantic v1 and v2. To achieve this we use the pattern
try:
from pydantic.v1 import Something
except ImportError:
from pydantic import Something
This should be compatible with all pydantic versions back to 1.7.4. The custom json_encoder has also been updated to handle both v1 and v2 model classes.