Skip to content

[BUG][PYTHON] JSON serialization fails for UUID fields in generated Python #22063

Open

Description

@ridi121983

I am using the maven plugin openapi-generator-maven-plugin (python generator), to generate Python code that includes UUID fields. Since 7.15 version of this plugin, the to_json method of the generated python object containing an UUID field leads to this error: Object of type UUID is not JSON serializable error

There is an example to reproduce the issue

components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: string
          format: uuid
from my_api.model.my_object import MyObject
import uuid

obj = MyObject(id=uuid.uuid4())
json_str = obj.to_json()

Activity

  1. EspenHa commented on Oct 12, 2025

    @EspenHa
    Contributor

    I was able to reproduce this issue. I found a workaround by using this instead: obj.model_dump_json(by_alias=True, exclude_unset=True), based on this TODO in the current template:

    # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead

    It seems this TODO was planned for pydantic v2, so maybe it is time for a switch over to this method instead of the old method?

  2. fa0311 commented on Jul 20, 2026

    @fa0311
    Contributor

    This should be fixed since #23210 — to_json no longer goes through plain json.dumps. Just verified a uuid field on master and it serializes fine now. Please retest with the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions