Home icon indicating copy to clipboard operation
Home copied to clipboard

Unable to deserialize property when property name case doesn't match

Open torbacz opened this issue 3 years ago • 3 comments

Library/API/IoT binding

nanoFramework.Json

Visual Studio version

No response

.NET nanoFramework extension version

No response

Target name(s)

No response

Firmware version

No response

Device capabilities

No response

Description

With current implementation of JSON serialization the library is checking for properties when deserializing with exact match case which is not the default behavior in .net

https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-character-casing "The web default is case-insensitive."

Solution: Create new static class with configuration options for json serialization with one new property PropertyNameCaseInsensitive. When deserializing use new flag to determinate either use case sensitive names or not.

How to reproduce

No response

Expected behaviour

No response

Screenshots

No response

Sample project or code

No response

Aditional information

No response

torbacz avatar Aug 06 '22 20:08 torbacz

This has already come up a few times. I'm a bit concerned on the performance impact that this will introduce... Code size will grow too, for sure. Maybe we should measure all this to have a better understanding on the impact.

josesimoes avatar Aug 07 '22 07:08 josesimoes

Well, I thinks it's just one setting - when comparing string you can specify if you want to ignore case or not.

string.Equals(val, "astringvalue", StringComparison.OrdinalIgnoreCase)

or

string.Equals(val, "astringvalue", StringComparison.Ordinal)

If it's implemented in nanoFrameowrk.

For sure, we should run some benchmarks before/after changes.

I've one more idea how to address this issue, but it's more complex and requires a lot of work. It will resolve some other issues also. I'll explain that in another issue.

torbacz avatar Aug 07 '22 08:08 torbacz

StringComparison is NOT available in nanoFramework. We're using github issues to track workloads and confirmed bugs. Let's not use this for discussions. Either start a discussion or better use Discord, which allows a more streamlined conversation. 😉

josesimoes avatar Aug 07 '22 08:08 josesimoes