Skip to content

why not generate fromJson and toJson functions in the *.g.dart file? #647

Closed
@TheDevelolper

Description

@TheDevelolper

So I'm using your library and the files are generating just fine.

I'm wondering though... I've got the following class:

import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import './product.dart';

part 'product_group.g.dart';

@JsonSerializable(nullable: false)
class ProductGroup {
  final List<Product> products;

  ProductGroup({this.products});

  factory ProductGroup.fromJson(Map<String, dynamic> json) =>
      _$ProductGroupFromJson(json);

  Map<String, dynamic> toJson() => _$ProductGroupToJson(this);
}

All my models are going to have the same factory method and toJson methods. Would it not be better to just generate these in the .g.dart file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions