Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get string without deserialization #88

Merged

Conversation

IIARROWS
Copy link
Contributor

Implemented a GetString method, with directly returns the string saved in local storage without any attempt to parse it.
This can lead to errors in case the string is a custom serialization (like from using Newtonsoft, see #18 ) or a string which simply starts/ends with double quotes or curly braces but it's not a valid Json.

This issue is also demonstrated by the sample app: saving valid json won't appear below "Value Read from local storage" which yield to a blank resul, as the API tries to parse the string.
"String Read from local storage", added in this PR, correctly displays the json string.

Added a new non-generic LocalStorageService.GetItemInternal, and replaced its use inside RaiseOnChangingSync method which directly returns an object, if deserialization fails, it catches the JsonException and returns the string as stored.

src/Blazored.LocalStorage/LocalStorageService.cs Outdated Show resolved Hide resolved
@@ -248,6 +266,38 @@ public T GetItemInternal<T>(string key)
}
}

public object GetItemInternal(string key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public object GetItemInternal(string key)
private object GetItemInternal(string key)

Is there a reason for this to be public? I'm guessing you've gone with this as the method this replaces was public but that shouldn't have been

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need to keep the old GetItemInternal method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I don't remember to have touched access level.
But it is used by RaiseOnChangingSync (that should be renamed RaiseOnChanging).

Co-authored-by: Chris Sainty <chrissainty@users.noreply.github.com>
@chrissainty chrissainty merged commit 054a872 into Blazored:master Jul 20, 2020
@chrissainty chrissainty mentioned this pull request Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants