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

pkg:json - Support DateTime attributes #56175

Open
azeldaniel opened this issue Jul 8, 2024 · 3 comments · May be fixed by #57063
Open

pkg:json - Support DateTime attributes #56175

azeldaniel opened this issue Jul 8, 2024 · 3 comments · May be fixed by #57063
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-json The json macro package type-enhancement A request for a change that isn't a bug

Comments

@azeldaniel
Copy link

Attempting to use a DateTime attribute within any @JsonCodable() annotated class throws an unsupported error. DateTime is a commonly used type in dart and other languages to represent timestamps for creation data points etc.

Consider the code:

@JsonCodable()
class Person {
  final DateTime birthday;
}

It throws the following errors:

Unable to deserialize type, it must be a native JSON type or a type with a `fromJson(Map<String, Object?> json)` constructor
Unable to serialize type, it must be a native JSON type or a type with a `Map<String, Object?> toJson()` method.

If supporting DateTime is not within the scope of this package, can you suggest a possible hack or workaround?

@dart-github-bot
Copy link
Collaborator

Summary: The pkg:json package currently doesn't support serializing and deserializing DateTime objects, resulting in errors when used within @JsonCodable() classes. The user requests support for DateTime or a workaround to handle timestamps.

@dart-github-bot dart-github-bot added area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Jul 8, 2024
@lrhn lrhn added pkg-json The json macro package and removed triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Jul 19, 2024
@devoncarew
Copy link
Member

@jakemac53, thoughts? Note that there's now a related CL.

@jakemac53
Copy link
Contributor

Reviewing the CL, I am generally fine with adding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-json The json macro package type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants