toAnnotationString method

String toAnnotationString()

Returns the @JsonKey annotation string to be applied to a field

Implementation

String toAnnotationString() {
  if (ignore == true) {
    return '@JsonKey(ignore: true)';
  }

  List<String> params = [];

  if (name != null) {
    params.add("name: '$name'");
  }
  if (defaultValue != null) {
    if (defaultValue is String) {
      params.add("defaultValue: '$defaultValue'");
    } else {
      params.add("defaultValue: $defaultValue");
    }
  }
  if (required != null) {
    params.add("required: $required");
  }
  if (includeIfNull != null) {
    params.add("includeIfNull: $includeIfNull");
  }
  if (includeFromJson != null) {
    params.add("includeFromJson: $includeFromJson");
  }
  if (includeToJson != null) {
    params.add("includeToJson: $includeToJson");
  }
  if (toJson != null) {
    params.add("toJson: $toJson");
  }
  if (fromJson != null) {
    params.add("fromJson: $fromJson");
  }

  if (params.isEmpty) {
    return '';
  }

  return '@JsonKey(${params.join(', ')})';
}