title: Flutter return parsing dynamic object from service
body: <p>I have created multiple models and using json_serialization</p>
  
  <p>Example Company and Employee and many more.</p>
  
  <pre><code>import 'package:json_annotation/json_annotation.dart';
  
  part 'company.g.dart';
  
  @JsonSerializable()
  class Company {
    Company({this.id, this.name});
  
    String id;
    String name;
  
  
    factory Company.fromJson(Map&lt;String, dynamic&gt; json) =&gt; _$CompanyFromJson(json);
  
    Map&lt;String, dynamic&gt; toJson() =&gt; _$CompanyToJson(this);
  }
  </code></pre>
  
  <pre><code>import 'package:json_annotation/json_annotation.dart';
  
  part 'employee.g.dart';
  
  @JsonSerializable()
  class Employee {
    Employee({this.id, this.name, this.email, this.phone, this.photo});
  
    String id;
    String name;
    String email;
    String phone;
    String photo;
  
    factory Employee.fromJson(Map&lt;String, dynamic&gt; json) =&gt; _$EmployeeFromJson(json);
  
    Map&lt;String, dynamic&gt; toJson() =&gt; _$EmployeeToJson(this);
  }
  </code></pre>
  
  <p>Now I want to create a reusable service that can return Stream with type Company, Employee or other types.
  I'm using Firebase so the return type is Map.</p>
  
  <p>example service class</p>
  
  <pre><code>class BaseService&lt;T&gt; {
    final String collection;
    CollectionReference _collectionRef;
  
    FirebaseBase({@required this.collection}) {
      _collectionRef = Firestore.instance.collection(collection);
    }
  
    Stream&lt;List&lt;T&gt;&gt; find() {
      return inColRef.snapshots().map((list) {
        return list.documents.map((doc) {
          final Map&lt;String, dynamic&gt; data = doc.data;
          data['id'] = doc.documentID;
          return data;
        }).toList();
      });
    }
  }
  </code></pre>
  
  <p>How do I convert the return data (Map) to a type Company or Employee.</p>
  
  <p>Those class can use the factory of fromJson(data). 
  But I can't return a T.fromJson(data).</p>
  
  <p>I would like to get</p>
  
  <pre><code>Stream&lt;List&lt;Company&gt;&gt; companies = ServiceBase('companies').find();
  Stream&lt;List&lt;Employee&gt;&gt; employees = ServiceBase('employee').find();
  </code></pre>