title: Save custom objects in session storage in Blazor WebAssembly application (using Blazored.SessionStorage)
body: <p>I´m trying to save some objects of classes which I have created to the session storage of my Blazor Wasm application to save the state after a refresh (F5). I followed the tutorial of Bradley Wells (<a href="https://wellsb.com/csharp/aspnet/blazor-write-to-localstorage/" rel="nofollow noreferrer">https://wellsb.com/csharp/aspnet/blazor-write-to-localstorage/</a>) assuming that everything works similar if I use session storage instead of local storage.</p>
  <p>If I tried my code using a basic datatype like string, it worked like a charm, the value &quot;testmessage&quot; was still displayed after a refresh of the page.</p>
  <pre><code>protected override async Task OnInitializedAsync()
  {
      testString = await sessionStorage.GetItemAsync&lt;string&gt;(&quot;sample&quot;);
  }
  
  // Method gets triggered on button press
  async Task TestMethodCanBeDeleted()
  {
      testString = &quot;testmessage&quot;;
      await sessionStorage.SetItemAsync&lt;string&gt;(&quot;sample&quot;, testString);
  }
  </code></pre>
  <p>As soon as I try to save e.g. an instance of the class MyCustomObject instead of string, it doesn´t work anymore. Do I have to create an instance of the class in the session storage at first? If yes, how.</p>
  <p>If someone knows another (maybe even better) way how to save &quot;non-basic&quot; datatypes in the session storage, please comment.</p>
  <p>Edit: Bradley Wells answered a comment on his page writing that it is possible to save objects to the session storage using Blazored, but didn´t explain how.</p>