json_to_dart icon indicating copy to clipboard operation
json_to_dart copied to clipboard

[request] add option for null handling

Open nashihu opened this issue 5 years ago • 1 comments

hello.

thanks for your great json to dart converter. regarding request, can you create option for null handling? for example, when the input is:

{
    "nopo": "PO00000390",
    "address": "Jl. Jend Sudirman No. 1"
}

the output is:

class Autogenerated {
  String nopo;
  int quantity;

  Autogenerated({this.nopo, this.quantity});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    nopo = json['nopo'] ?? "";
    quantity = json['quantity'] ?? 0;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['nopo'] = this.nopo;
    data['quantity'] = this.quantity;
    return data;
  }
}

thank you

nashihu avatar Dec 08 '19 15:12 nashihu

Hey this is a really good idea. I'll try to give this priority whenever I get my hands on this.

javiercbk avatar Dec 13 '19 13:12 javiercbk