Skip to content

[json_codable] Enhance JsonCodable to support custom key mappings between JSON and Dart fields #59718

@addalao

Description

@addalao

Description

The new JsonCodable macro in Dart is a great feature for JSON serialization, but it currently lacks support for custom JSON key mappings. This makes it difficult to map Dart fields to JSON keys with different naming conventions (e.g., fileName in Dart to file_name in JSON).

Example:

@JsonCodable()
class AudiosItem {
  final String id;

  // No support for custom JSON key mappings like this:
  // @JsonKey(name: 'file_name') or @JsonField(name: 'file_name')
  final String fileName;

  const AudiosItem({
    required this.fileName,
    required this.id,
  });
}

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