목차

json_serializable

build.yaml

targets:
  $default:
    builders:
      json_serializable:
        options:
          # Options configure how source code is generated for every
          # `@JsonSerializable`-annotated class in the package.
          #
          # The default value for each is listed.
          any_map: true
          explicit_to_json: true
          

field name

import 'package:json_annotation/json_annotation.dart';
 
part 'wine.g.dart';
 
@JsonSerializable()
class Wine {
  String id;
  @JsonKey(name: 'name_en')
  String nameEn;
  @JsonKey(name: 'name_ko')
  String nameKo;
  List<String> images;
  List<Map<String, String>> sell;
 
  Wine({this.id, this.nameEn, this.nameKo, this.images, this.sell});
 
  factory Wine.fromJson(Map<String, dynamic> json) => _$WineFromJson(json);
 
  Map<String, dynamic> toJson() => _$WineToJson(this);
}


관련 문서