{"action":"opened","issue":{"url":"https://api.github.com/repos/Cretezy/redux_persist/issues/12","repository_url":"https://api.github.com/repos/Cretezy/redux_persist","labels_url":"https://api.github.com/repos/Cretezy/redux_persist/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/Cretezy/redux_persist/issues/12/comments","events_url":"https://api.github.com/repos/Cretezy/redux_persist/issues/12/events","html_url":"https://github.com/Cretezy/redux_persist/issues/12","id":325615833,"number":12,"title":"SerializationException: Save: Converting object to an encodable object failed","user":{"login":"nicolashemonic","id":1469457,"avatar_url":"https://avatars0.githubusercontent.com/u/1469457?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolashemonic","html_url":"https://github.com/nicolashemonic","followers_url":"https://api.github.com/users/nicolashemonic/followers","following_url":"https://api.github.com/users/nicolashemonic/following{/other_user}","gists_url":"https://api.github.com/users/nicolashemonic/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolashemonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolashemonic/subscriptions","organizations_url":"https://api.github.com/users/nicolashemonic/orgs","repos_url":"https://api.github.com/users/nicolashemonic/repos","events_url":"https://api.github.com/users/nicolashemonic/events{/privacy}","received_events_url":"https://api.github.com/users/nicolashemonic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-23T09:10:36Z","updated_at":"2018-05-23T09:10:36Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI installed latest version:\r\n\r\n```\r\nredux_persist:\r\nredux_persist_flutter:\r\n```\r\n\r\nWhen an action is dispatched the following exception is thrown:\r\n\r\n__SerializationException: Save: Converting object to an encodable object failed: Instance of 'AppState'__\r\n\r\n```\r\n[VERBOSE-2:dart_error.cc(16)] Unhandled exception:\r\nSerializationException: Save: Converting object to an encodable object failed: Instance of 'AppState'\r\n#0      Persistor.save (package:redux_persist/redux_persist.dart:222:7)\r\n<asynchronous suspension>\r\n#1      Persistor.createMiddleware.<anonymous closure> (package:redux_persist/redux_persist.dart:84:13)\r\n#2      Store._createDispatchers.<anonymous closure> (package:redux/src/store.dart:238:43)\r\n#3      Store.dispatch (package:redux/src/store.dart:250:20)\r\n#4      LogInForm.build.<anonymous closure>.<anonymous closure> (file:///Users/nicolas/Projects/Availpro/mobile-starter-kit/lib/containers/log_in_form.dart:14:21)\r\n#5      LogInFormState.onFormSubmit (file:///Users/nicolas/Projects/Availpro/mobile-starter-kit/lib/widgets/log_in_form.dart:22:20)\r\n#6      LogInFormState.buildFormSubmitButton.<anonymous closure> (file:///Users/nicolas/Projects/Availpro/mobile-starter-kit/lib/widgets/log_in_form.dart:86:28)\r\n#7      _InkResponseState._handleTap (package:flutte<…>\r\n```\r\n\r\nFind below redux_persist implementation.\r\n\r\n### Main\r\n```dart\r\nvoid main() {\r\n  final persistor = new Persistor<AppState>(\r\n      storage: new FlutterStorage(\"mobile-starter-kit\"),\r\n      decoder: AppState.fromJson);\r\n\r\n  final store = new Store<AppState>(appReducer,\r\n      initialState: new AppState(\r\n        counter: new CounterState(),\r\n        authentication: new AuthenticationState(),\r\n      ),\r\n      middleware: [persistor.createMiddleware(), thunkMiddleware]);\r\n\r\n  persistor.load(store);\r\n  runApp(App(store: store));\r\n}\r\n```\r\n\r\n### App State\r\n```dart\r\nclass AppState {\r\n  final CounterState counter;\r\n  final AuthenticationState authentication;\r\n\r\n  const AppState({@required this.counter, @required this.authentication});\r\n\r\n  static AppState fromJson(dynamic json) => new AppState(\r\n      counter: json['counter'], authentication: json['authentication']);\r\n\r\n  dynamic toJson() => {'counter': counter, 'authentication': authentication};\r\n}\r\n```\r\n\r\n### App Reducer\r\n```dart\r\nAppState appReducer(AppState state, action) {\r\n  if (action is PersistLoadedAction<AppState>) {\r\n    return action.state ?? state;\r\n  }\r\n  return new AppState(\r\n      counter: counterReducer(\r\n        state.counter,\r\n        action,\r\n      ),\r\n      authentication: authenticationReducer(state.authentication, action));\r\n}\r\n```\r\n\r\nThanks for your help !"}}
{"actor":{"display_login":"nicolashemonic"}}