genericArgumentFactories property

bool genericArgumentFactories

When true on classes with type parameters (generic types), extra "helper" parameters will be generated for fromJson and/or toJson to support serializing values of those types.

For example, the generated code for

@JsonSerializable(genericArgumentFactories: true)
class Response<T> {
  int status;
  T value;

Looks like

Response<T> _$ResponseFromJson<T>(
  Map<String, dynamic> json,
  T Function(Object json) fromJsonT,
) {
  return Response<T>()
    ..status = json['status'] as int
    ..value = fromJsonT(json['value']);

Map<String, dynamic> _$ResponseToJson<T>(
  Response<T> instance,
  Object Function(T value) toJsonT,
) =>
    <String, dynamic>{
      'status': instance.status,
      'value': toJsonT(instance.value),

Note: this option has no effect on classes class without type parameters. A warning is printed in such cases.

Note: if this option is set for all classes in a package via build.yaml it is only applied to classes with type parameters – so no warning is printed.


final bool genericArgumentFactories