toJsonFunctions method

String toJsonFunctions(
  1. String className
)

Implementation

String toJsonFunctions(String className) {
  var result = '';

  bool find(DartDeclaration e) => e.name != null && e.ignored == false;
  final fromJsonBody = ModelTemplates.indented(where(find).map((e) => e.fromJsonBody()).join(',\n').trim());
  final toJsonBody = ModelTemplates.indented(where(find).map((e) => e.toJsonBody(className)).join(',\n').trim());

  result = 'factory $className.fromJson(Map<String,dynamic> json) => $className(\n$fromJsonBody\n);\n\n';
  result += 'Map<String, dynamic> toJson() => {\n$toJsonBody\n};';

  return ModelTemplates.indented(result);
}