Skip to content

GSOC : Add JSON serialization support for Python Dubbo #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aditya0yadav
Copy link

@aditya0yadav aditya0yadav commented Jun 9, 2025

What is the purpose of the change

ISSUE: #issue_number

Brief changelog

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

@aditya0yadav
Copy link
Author

Hi @cnzakii,
Aditya here 👋

This is an exemplary pull request to demonstrate JSON serialization support in the Python Dubbo framework.

Purpose

The goal of this PR is to add JSON serialization capabilities using Pydantic, by building a modular structure around DubboCodec and the codec registry. This helps streamline how JSON is handled and decoded between services in a clean and extensible manner.

Highlights

  • Introduced modular codec handling using DubboCodec
  • JSON serialization with Pydantic models for both request and response

Example

Client:

self.unary = client.unary(
    method_name="unary",
    codec_type="json",
    request_model=UserListResponse,
    response_model=UserRequest
)

Server:

method_handler = RpcMethodHandler.unary(
    UserServiceHandler().list_users,
    method_name="unary",
    codec_type="json",
    request_model=UserRequest,
    response_model=UserListResponse
)

Notes

  • Variable naming has been done thoughtfully, but open to suggestions if any part feels unclear.
  • Please review and let me know if any adjustments are needed.
  • I can also provide the full client/server examples if required.

Thanks for reviewing this! Let me know your thoughts.

@aditya0yadav aditya0yadav changed the title Add JSON serialization support for Python Dubbo GSOC : Add JSON serialization support for Python Dubbo Jun 9, 2025
@cnzakii
Copy link
Member

cnzakii commented Jun 10, 2025

@aditya0yadav
Hi, I'll review the code as soon as possible.
In addition, to improve communication efficiency, it would be better to use an instant messaging tool since email can be a bit slow.
Do you use DingTalk, WeChat, or any other messaging app? Or is there a communication tool you prefer?

@aditya0yadav
Copy link
Author

@cnzakii
Sorry, I forgot to add the license header in the file
I just added that

@aditya0yadav
Copy link
Author

aditya0yadav commented Jun 13, 2025

@cnzakii @AlbumenJ Just wanted to check — is the design suitable for JSON serialization? If yes, I’ll go ahead and start working on Protobuf

@cnzakii
Copy link
Member

cnzakii commented Jun 18, 2025

@aditya0yadav

Code Review Report and Suggestions

  1. All .DS_Store files should be excluded from the repository (e.g., via .gitignore).
  2. The current CodecRegistry implementation should be replaced with Dubbo's ExtensionLoader mechanism to ensure that all extensions are centrally managed and follow a unified strategy.
  3. Dependencies on libraries such as orjson and pydantic should be made optional. These modules should be structured as optional extensions, only imported when explicitly enabled by the user.
  4. The current implementation of JsonCodec lacks generality. At a minimum, it should support Python’s basic data types as well as dataclass and namedtuple.
  5. Although the JsonCodec class supports serializing multiple types, it only supports deserializing from bytes into a single type. This design is arguably suboptimal, as it forces users to implement a separate CustomJsonCodec for each type. This goes against the principle of ease-of-use and reusability.

Due to the limited amount of code submitted, the review is brief but focused. I hope these suggestions are helpful to your development process.

@aditya0yadav
Copy link
Author

@cnzakii Thanks for the suggestion.
I will use the suggested approach and re-PR after checking thoroughly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants