dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

VMSerializer dispatch with arrays #149

Closed mikaelliljedahl closed 5 years ago

mikaelliljedahl commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

mikaelliljedahl commented 5 years ago

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: https://github.com/dsuryd/dotNetify/pull/153

dsuryd commented 5 years ago

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