title: Unhandled Exception: DioError [DioErrorType.DEFAULT]: Converting object to an encodable object failed
body: <p>I have an object that i want to send to an api through dio when i try this i get Unhandled Exception: DioError [DioErrorType.DEFAULT]: Converting object to an encodable object failed. I hav also tried converting the object to Json but i still get another error which i will mention down below. </p>
  
  <pre><code>  static Future&lt;DiagnosisModel&gt; doDiagnosis(String url, String id,String choiceId, bool initial) async{
  Dio dio = new Dio();
  dio.options.headers['content-Type'] = 'application/json';
  dio.options.headers['App-Id'] = ChatBotApi.applicationId;
  dio.options.headers['App-Key'] = ChatBotApi.applicationKey;
  Response response;
  
  DiagnosisSendingModel diagnosisSendingModel;
  Evidence evidence;
  
  if(initial){
    evidence = Evidence();
    diagnosisSendingModel = DiagnosisSendingModel();
    diagnosisSendingModel.evidence = List&lt;Evidence&gt;();
    evidence.id = id;
    evidence.initial = initial;
  
  
    diagnosisSendingModel.sex = "male";
    diagnosisSendingModel.age = 23;
    diagnosisSendingModel.evidence.add(evidence);
  
  
    response = await dio.post(
        url,
        data: diagnosisSendingModel
    );
  }else{
    evidence = Evidence();
    diagnosisSendingModel = DiagnosisSendingModel();
    evidence.id = id;
    if(choiceId == "present"){
      evidence.choiceId = ChoiceId.PRESENT;
    }else{
      evidence.choiceId = ChoiceId.ABSENT;
    }
  
    diagnosisSendingModel.sex = "male";
    diagnosisSendingModel.age = 23;
    diagnosisSendingModel.evidence.add(evidence);
  
    response = await dio.post(
        url,
        data: diagnosisSendingModel
    );
  }
  
  
  DiagnosisModel diagnosisModel;
  if(response.statusCode == 200){
    diagnosisModel = DiagnosisModel.fromJson(response.data);
    print(diagnosisModel);
  }else{
    throw("Error ${response.statusCode}");
  }
  
  return diagnosisModel;
  }
  </code></pre>
  
  <p>I have also tried converting to json and i still get an error   </p>
  
  <pre><code>Unhandled Exception: Converting object to an encodable object failed: Instance of 'DiagnosisSendingModel'
  </code></pre>
  
  <p>The code for that below </p>
  
  <pre><code>  static Future&lt;DiagnosisModel&gt; doDiagnosis(String url, String id,String choiceId, bool initial) async{
  Dio dio = new Dio();
  dio.options.headers['content-Type'] = 'application/json';
  dio.options.headers['App-Id'] = ChatBotApi.applicationId;
  dio.options.headers['App-Key'] = ChatBotApi.applicationKey;
  Response response;
  
  DiagnosisSendingModel diagnosisSendingModel;
  Evidence evidence;
  
  if(initial){
    evidence = Evidence();
    diagnosisSendingModel = DiagnosisSendingModel();
    diagnosisSendingModel.evidence = List&lt;Evidence&gt;();
    evidence.id = id;
    evidence.initial = initial;
  
  
    diagnosisSendingModel.sex = "male";
    diagnosisSendingModel.age = 23;
    diagnosisSendingModel.evidence.add(evidence);
  
  var jsonVar = json.encode(diagnosisSendingModel);
    response = await dio.post(
        url,
        data: jsonVar
    );
  }else{
    evidence = Evidence();
    diagnosisSendingModel = DiagnosisSendingModel();
    evidence.id = id;
    if(choiceId == "present"){
      evidence.choiceId = ChoiceId.PRESENT;
    }else{
      evidence.choiceId = ChoiceId.ABSENT;
    }
  
    diagnosisSendingModel.sex = "male";
    diagnosisSendingModel.age = 23;
    diagnosisSendingModel.evidence.add(evidence);
    var jsonVar = json.encode(diagnosisSendingModel);
    response = await dio.post(
        url,
        data: jsonVar
    );
  }
  
  
  DiagnosisModel diagnosisModel;
  if(response.statusCode == 200){
    diagnosisModel = DiagnosisModel.fromJson(response.data);
    print(diagnosisModel);
  }else{
    throw("Error ${response.statusCode}");
  }
  
  return diagnosisModel;
  }
  </code></pre>
  
  <p>Below is my model</p>
  
  <pre><code>  String sex;
    int age;
    List&lt;Evidence&gt; evidence;
    ExtrasSending extras;
  
    DiagnosisSendingModel({
      this.sex,
      this.age,
      this.evidence,
      this.extras,
    });
  
    factory DiagnosisSendingModel.fromJson(Map&lt;String, dynamic&gt; json) =&gt; DiagnosisSendingModel(
      sex: json["sex"],
      age: json["age"],
      evidence: List&lt;Evidence&gt;.from(json["evidence"].map((x) =&gt; Evidence.fromJson(x))),
      extras: ExtrasSending.fromJson(json["extras"]),
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      "sex": sex,
      "age": age,
      "evidence": List&lt;dynamic&gt;.from(evidence.map((x) =&gt; x.toJson())),
      "extras": extras.toJson(),
    };
  }
  
  class Evidence {
    String id;
    ChoiceId choiceId;
    bool initial;
  
    Evidence({
      this.id,
      this.choiceId,
      this.initial,
    });
  
    factory Evidence.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Evidence(
      id: json["id"],
      choiceId: choiceIdValues.map[json["choice_id"]],
      initial: json["initial"] == null ? null : json["initial"],
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      "id": id,
      "choice_id": choiceIdValues.reverse[choiceId],
      "initial": initial == null ? null : initial,
    };
  }
  
  enum ChoiceId { PRESENT, ABSENT }
  
  final choiceIdValues = EnumValues({
    "absent": ChoiceId.ABSENT,
    "present": ChoiceId.PRESENT
  });
  
  class ExtrasSending {
    bool enableTriage5;
  
    ExtrasSending({
      this.enableTriage5,
    });
  
    factory ExtrasSending.fromJson(Map&lt;String, dynamic&gt; json) =&gt; ExtrasSending(
      enableTriage5: json["enable_triage_5"],
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      "enable_triage_5": enableTriage5,
    };
  }
  
  class EnumValues&lt;T&gt; {
    Map&lt;String, T&gt; map;
    Map&lt;T, String&gt; reverseMap;
  
    EnumValues(this.map);
  
    Map&lt;T, String&gt; get reverse {
      if (reverseMap == null) {
        reverseMap = map.map((k, v) =&gt; new MapEntry(v, k));
      }
      return reverseMap;
    }
  } ```
  </code></pre>