Skip to content
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

[Update] Change JsonConverter to allow dynamic type serialization #772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eddy1937
Copy link

PR Title:

Allow json.JsonConverter to support dynamic type serialization for more flexibility


PR Description:

Background / Problem:

When using swagger-dart-code-generator, the current implementation of json.JsonConverter forces type serialization to String, which limits flexibility when serializing custom types. For example, when attempting to serialize a DateTime object to a Unix timestamp (int), the code forces the output type to be String, leading to serialization errors.

Proposed Solution:

This PR modifies the generated code to use json.JsonConverter<T, dynamic> instead of json.JsonConverter<T, String>. This change allows for more flexibility in serializing various types, such as serializing DateTime to int (Unix timestamp) and other custom types.

Key Changes:

  • Updated json.JsonConverter to support dynamic types instead of forcing the output to String.
  • Ensured that the serialization logic can now handle different types, such as converting DateTime to a Unix timestamp (int).

Test Cases:

  • I have tested this change locally and confirmed that it works as expected with custom serialization (e.g., serializing DateTime to int).
  • No existing functionality has been broken by this update.

Related Issue:

This PR addresses issue #771.

@diegotori
Copy link
Contributor

@Vovanella95 any progress on this?

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