Skip to content

JsonCodable should use type in Xxx.fromJson/toJson as representation in json #56346

@a14n

Description

@a14n

On decimal package someone reported an issue with JsonCodable. He tried the following code:

@JsonCodable()
class User {
  final Decimal? test;
  User(this.test);
}

As Decimal.fromJson accepts String as parameter he get an error because the generated code use a Map<String, Object?> as input.

It would be great if JsonCodable could read the type present in Xxx.fromJson and use it as serialization format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-pkgUsed for miscellaneous pkg/ packages not associated with specific area- teams.pkg-jsonThe json macro packagetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions