title: Casting an object in Flutter/Dart returns _HashSet
body: <p>I am having some problem in Flutter with casting a dynamic to a custom object. I receive JSON as response from a web service, which I store as an instance of my object in a class as dynamic together with some other meta information. When I try to cast that object to my desired class (e.g. LoginReply) I keep getting the following error message: <code>Expected a value of type 'LoginReply', but got one of type '_HashSet&lt;LoginReply&gt;'</code></p>
  <p>Here is my response class that stores the reply object:</p>
  <pre><code>class DioResponse {
  
    String? error;
    dynamic object;
  
    DioResponse(this.error, this.object);
  
    bool get isSuccessful =&gt; error == null || error!.isEmpty;
  
    T get&lt;T extends dynamic&gt;() {
      print(&quot;Object: $object&quot;);
      return object.cast&lt;T&gt;();
    }
  
  }
  </code></pre>
  <p>I serialize the JSON response like this:</p>
  <pre><code>LoginReply _serializeResponse(Map&lt;String, dynamic&gt; json) {
      LoginReply reply = LoginReply.fromJson(json);
      if (!reply.header!.successful) {
        errorMessage.value = &quot;${reply.header!.errorCode}: ${reply.header!.errorMessage}&quot;;
        return LoginReply();
      }
      AppConfig.persistString(&quot;token&quot;, reply.token!);
      return reply;
    }
  </code></pre>
  <p>And here is how I try to access the DioReponse.object / LoginReply:</p>
  <pre><code>DioResponse response = await handler.post(Globals.nodeAddress, ......);
      if (response.isSuccessful) {
        //LoginReply reply = response.get&lt;LoginReply&gt;();
        print(&quot;Object: ${response.object}&quot;);
        LoginReply reply = response.object as LoginReply;
  </code></pre>
  <p>The print output on the second last line prints: <code>Object: {Instance of 'LoginReply'}</code> which makes the whole error even harder to understand for me.</p>