glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.16k stars 1.06k forks source link

[Dart] JSON Serializable Option #1620

Open jordanliu opened 3 years ago

jordanliu commented 3 years ago

Add JSON Serializable Option under Dart, adds the annotation and converts the json encoders/decoders to be handled by the package



import 'package:json_annotation/json_annotation.dart';

part 'example.g.dart';

@JsonSerializable(nullable: false)
class Person {
  final String firstName;
  final String lastName;
  final DateTime dateOfBirth;
  Person({this.firstName, this.lastName, this.dateOfBirth});
  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
  Map<String, dynamic> toJson() => _$PersonToJson(this);
}
sagarmahobia commented 2 years ago

https://deploy-preview-3--dart-quicktype.netlify.app/

https://github.com/chunlee-thong/dart-quicktype/pull/3

Add JSON Serializable Option under Dart, adds the annotation and converts the json encoders/decoders to be handled by the package

import 'package:json_annotation/json_annotation.dart';

part 'example.g.dart';

@JsonSerializable(nullable: false)
class Person {
  final String firstName;
  final String lastName;
  final DateTime dateOfBirth;
  Person({this.firstName, this.lastName, this.dateOfBirth});
  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
  Map<String, dynamic> toJson() => _$PersonToJson(this);
}