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

VMSerializer dispatch with arrays #149

Closed
mikaelliljedahl opened this issue Nov 23, 2018 · 4 comments
Closed

VMSerializer dispatch with arrays #149

mikaelliljedahl opened this issue Nov 23, 2018 · 4 comments
Labels

Comments

@mikaelliljedahl
Copy link

Hi,

it seems since the 3.1 update a change in VMSerializer.Serialize causes an application that sends an array of integers in a dispatch/UpdateVM (e. g. NewValue = "[\r\n 481,\r\n 541\r\n]" in ) to get an exception since a JArray cannot be JSON-serialised.

For me, adding these 2 rows in VMSerializer at row 49, solved the issue and made the application continue to work as before (i made a local copy of the project and added a reference to that instead of the nuget to be able to debug).

if (viewModel is JArray)
{
return viewModel.ToString();
}

Not sure if this is a feasible solution to be part of a future release, but if it is, could you please include this fix?

It worked nicely in the 3.0.1 release, so there might be an prettier fix.

Best Regards
Mikael

@dsuryd
Copy link
Owner

dsuryd commented Nov 23, 2018

Adding to line 44 will fix it too?

if (viewModel is string || viewModel is JArray || !viewModel.GetType().GetTypeInfo().IsClass)
   return Convert.ToString(viewModel);

If you could send me a PR with a unit test, I'll incorporate it in the next release.

@mikaelliljedahl
Copy link
Author

Yes, adding it to line 44 works too. I will try to make a PR (it will be my first on github ever).

@dsuryd dsuryd added the bug label Nov 24, 2018
@mikaelliljedahl
Copy link
Author

I hope it's ok that I just added a unit test to the existing SimpleListVM-test. I kind of had everything needed to make a sample with an array of id's.
Here is the PR:
#153

dsuryd added a commit that referenced this issue Nov 26, 2018
#149 Add JArray check to VMSerializer.
@dsuryd
Copy link
Owner

dsuryd commented Nov 26, 2018

Thank you, and congrats on your first successful github PR :) 👍

@dsuryd dsuryd closed this as completed Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants