Comments (11)
@dave-bt To work around the problem before the fix is released you can force the Json serializer to always use lowercase property names like that:
public class Post
{
[JsonPropertyName("author")]
public string Author { get; set; } = "";
[JsonPropertyName("content")]
public string Content { get; set; } = "";
}
You may need to add reference to the System.Text.Json
package however if your class is located in netstandard2.1
project (default with Blazor .Shared projects):
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.6.0-preview6.19303.8" />
</ItemGroup>
from signalr.
I have the exact same issue. If I retrieve the object into my Blazor page using HttpClient it is populated, if I send the same object to my SignalR handler then the object's fields are all null. I may also be doing something very wrong - this is all rather new to me.
from signalr.
Ok, I found out that the problem is related to case-sensitivity of names of properties in my object.
The object that I was trying to send down SignalR looks like that:
public class Post
{
public string Author { get; set; }
public string Text { get; set; }
}
Unfortunately, the System.Text.Json
serializer on the server makes all property names lower-case before sending the object representation down the pipe. Client however, is more picky and expects exactly the same casing and thus, cannot match property names.
After changing my object to:
public class Post
{
public string author { get; set; }
public string text { get; set; }
}
It started working.
from signalr.
I can see that I had .AddNewtonsoftJson()
in my sample project after all, but it doesn't change anything because System.Text.Json
and Newtonsoft Json both make serialized property names case-insensitive.
I can see that .Net client for SignalR core changed to also accept case-insensitive properties by default so it should be implemented as such in this client as well.
from signalr.
This probably has to happen in HubConnection.cs
where JsonSerializer.Parse<>()
is called bunch of times.
That's where case-(in)sensivity matters.
Maybe it should be configurable when setting up the hub connection like with AddJsonProtocol
of regular SignalR client. Or maybe this Blazor client has limited scope and we shouldn't be so flexible and enable only the default. I can prepare some PR for the latter one if that's the way the maintainers want to go with.
from signalr.
Hello @MiKom
Please open the PR if you are in the mood for that. It will be very much appreciated.
However, keep in mind that this package tries to only wrap the JS client as much as possible,
So if there is something that the C# is interfering we should indeed tackle.
Thanks!
from signalr.
I'll get to it tomorrow, it's getting late here :)
from signalr.
@MiKom Thank you very much indeed for that. Works a treat!
from signalr.
The preview7 package was published and it supports the JsonPropertyName
. Please try it out.
from signalr.
The property names parsing is still not case-insensitive, also in preview7 right? Are there any plans to make it so?
from signalr.
Yes, the current System.Text.Json
requires you to use JsonPropertyName
.
from signalr.
Related Issues (20)
- Serverside example HOT 3
- JsRuntime on Server side HOT 1
- InvalidOperationException: JSRuntime must be set up correctly and must be an instance of JSRuntimeBase to use DotNetObjectRef. HOT 2
- Update to preview 8 HOT 1
- .net 3 preview 9 build error HOT 3
- Serialization Issue / Configuration HOT 6
- Cannot deserialize decimal with MessagePack and System.Text.Json HOT 1
- HubConnectionBuilder throws NullReferenceException HOT 6
- Support automatic reconnects and State on HubConnection HOT 4
- Non-generic overload of the On method? HOT 3
- Server Hub receives ValueTuple with default values HOT 2
- Why is this needed? HOT 1
- Preview 2 HOT 1
- Why JWT is being send in a query string parameter instead of its proper header? HOT 1
- Can't serialize poco class HOT 5
- Upgrading Blazor WebAssembly to 3.1.0-preview4.19579.2 leads to an error: Could not find 'BlazorExtensions' in 'window'. HOT 10
- Upgrading to .NET Standard 2.1 in the Blazor client-side project causes a runtime error HOT 1
- This might be obsolete now HOT 1
- examples needed
- How can we add support for Additional languages?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from signalr.