Skip to content

Provide some means to generate from/toJson for compatible types for other code generators #1496

@TekExplorer

Description

@TekExplorer

json serializable is a powerful generator. Often, other generators will want to be able to generate to/fromJson functions for its own use.

This can include retrofit, riverpod's v3 experimental @JsonPersist(), and plenty more, which are effectively forced to re-implement json_serializable, which will never be as good, and will always be missing features.

I noticed this issue when i tried using @JsonPersist() with a type that uses generic argument factories, and it failed to generate correct code. the same was true of Slugid, which does not have a fromJson constructor, and it does not have a toJson method. with jsonSerializable, i could tell json_serializable to use Slugid(json) and slugid.toString() as is proper, but attempting to support that in riverpod would be highly unreasonable, forcing me to wrap the class to use json_serializable on, which is bad API

Often, this can involve programatically supporting generic argument factories, enums, and even classes that dont directly support serialization, which could benefit from somehow applying @JsonKey and Converters

I'm not sure what the best way to do this is, but it would be a benefit if we could keep all serialization code centralized here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions