title: How to decode from json in this situation?
body: <p>I am saving an entire class as a json object on my Parse Back4App server. It was a pain getting the object to parse to json because I needed to turn many properties into string in both nested class Book and main class DatabaseSyncItem. Now I have no idea how to turn this json object back into a DatabaseSyncObject. I assume the same would go for getting the nested json book objects back to object model, that is that it wont work this way.</p>
  <p>I'm getting errors and have no success. If I try to access a specific index from my list of json objects in main I can get somewhere but this is very messy. What would you do in this situation? Help me out here, my first time working with json.</p>
  <p>Tried applying these posts but no workey:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/64234394/json-encoding-in-dart">JSON encoding in Dart</a></li>
  <li><a href="https://stackoverflow.com/questions/56406601/how-to-encode-an-object-to-json-in-flutter">How to encode an object to json in Flutter</a></li>
  </ul>
  <pre><code>import 'dart:convert';
  import 'dart:io';
  import 'package:hive/hive.dart';
  import 'package:parse_server_sdk/parse_server_sdk.dart';
  import 'package:service_database_sync/data/books_hardcoded.dart';
  import 'package:service_database_sync/models/book_model.dart';
  import 'package:service_database_sync/models/database_sync_model.dart';
  import 'package:service_database_sync/services/demo_services.dart';
  import 'package:service_database_sync/services/server_database_services.dart';
  
  Future&lt;void&gt; main(List&lt;String&gt; arguments) async {
    Hive.init('hive_database');
    Hive.registerAdapter(BookAdapter());
    await Parse().initialize(
      ServerDatabaseServices().keyApplicationId,
      ServerDatabaseServices().keyParseServerUrl,
      clientKey: ServerDatabaseServices().keyClientKey,
      debug: true,
    );
  
    final test = updateLocalDatabase();
    Future&lt;List&gt; getList() {
      return Future.value(test);
    }
  
    var list = await getList();
    var jsonObject = list[2]['DatabaseSyncItem'];
    // var backToObject = jsonDecode(jsonObject); // error: type '_InternalLinkedHashMap&lt;String, dynamic&gt;' is not a subtype of type 'String'
    var backToObject = DatabaseSyncItem.fromJson(jsonObject); // error: type '_InternalLinkedHashMap&lt;String, dynamic&gt;' is not a subtype of type 'Book'
    print(backToObject);
  }
  
  // This method will get server database
    Future&lt;List&lt;ParseObject&gt;&gt; updateLocalDatabase() async {
      final events = QueryBuilder&lt;ParseObject&gt;(ParseObject('Event'));
      final apiResponse = await events.query();
      if (apiResponse.success &amp;&amp; apiResponse.result != null) {
        return apiResponse.results;
      } else {
        return [];
      }
    }
  
  part 'database_sync_model.g.dart';
  
  @HiveType(typeId: 1)
  class DatabaseSyncItem {
    @HiveField(0)
    Book previousBookValue;
  
    @HiveField(1)
    Book updatedBookValue;
  
    @HiveField(2)
    DateTime dateAdded;
  
    @HiveField(3)
    DateTime lastModified;
  
    @HiveField(4)
    DatabaseAction entryAction;
  
    DatabaseSyncItem({
      this.previousBookValue,
      this.updatedBookValue,
      this.dateAdded,
      this.lastModified,
      this.entryAction,
    });
  
    @override
    String toString() {
    return '''
    previousValue: $previousBookValue
    updatedValue: $updatedBookValue
    dateAdded: $dateAdded
    lastModified: $lastModified
    entryAction: $entryAction
    ''';
     }
  
    // Turn json back into data model
    DatabaseSyncItem.fromJson(Map&lt;String, dynamic&gt; json)
        : previousBookValue = json['previousBookValue'],
          updatedBookValue = json['updatedBookValue'],
          dateAdded = json['dateAdded'],
          lastModified = json['lastModified'],
          entryAction = json['entryAction'];
  
    // Turn data model into json
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          'previousBookValue': previousBookValue,
          'updatedBookValue': updatedBookValue,
          'dateAdded': dateAdded,
          'lastModified': lastModified,
          'entryAction': entryAction.toString(),
        };
  }
  
  enum DatabaseAction {
    create,
    update,
    delete,
  }
  
  import 'package:hive/hive.dart';
  part 'book_model.g.dart';
  
  @HiveType(typeId: 0)
  class Book {
    @HiveField(0)
    String title;
  
    @HiveField(1)
    String author;
  
    @HiveField(2)
    DateTime publishingDate;
  
    @HiveField(3)
    DateTime dateAdded;
  
    @HiveField(4)
    DateTime lastModified;
  
    Book({
      this.title,
      this.author,
      this.publishingDate,
      this.dateAdded,
      this.lastModified,
    });
  
    @override
    String toString() {
    return '''
    title: $title
    author: $author
    publishingDate: $publishingDate
    dateAdded: $dateAdded
    lastModified $lastModified
    ''';
     }
  
    Book.fromJson(Map&lt;String, dynamic&gt; json)
        : title = json['title'],
          author = json['author'],
          publishingDate = json['publishingDate'],
          dateAdded = json['dateAdded'],
          lastModified = json['lastModified'];
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          'title': title,
          'author': author,
          'publishingDate': publishingDate.toIso8601String(),
          'dateAdded': dateAdded.toIso8601String(),
          'lastModified': lastModified.toIso8601String()
        };
  }
  
  </code></pre>