Skip to content

[json_codable] the object passed to fromJson is not necessarily a Map #59580

@cedvdb

Description

@cedvdb

Currently json_codable assumes that a Map is passed to the fromJson constructor when that constructor is defined by the user.

This is not supported:

@JsonCodable()
class A {
  final CustomStringSerialization customStringSerializationField;
}

class CustomStringSerialization {
  final String a;

  CustomStringSerialization(this.a);

  String toJson() => a;

  factory CustomStringSerialization.fromJson(String a) =>
      CustomStringSerialization(a);
}

Use cases:

  • deserializing values to object, for example a 'EUR' value could be deserialized to a currency object with its format method
  • it will be necessary for enum support

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