Schema.NET icon indicating copy to clipboard operation
Schema.NET copied to clipboard

Fix for null string values

Open RehanSaeed opened this issue 3 years ago • 4 comments
trafficstars

Fixes:

  • https://github.com/RehanSaeed/Schema.NET/issues/389

RehanSaeed avatar Feb 09 '22 17:02 RehanSaeed

Looks like our issue is this block of code in S.T.J: https://source.dot.net/#System.Text.Json/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs,353

There are a couple of flags around there that we might be able to toggle to get this to behave correctly.

Turnerj avatar Feb 10 '22 01:02 Turnerj

I should mention - that the block of code I linked to is likely based on the master/main code in the Runtime, not necessarily what we are using. ~We don't have individual control of HandleNullOnRead currently, just a HandleNull property which does read and write.~ (Edit: HandleNullOnRead is internal)

I imagine (though haven't confirmed) is that if we enable HandleNull, it might mean that null/default values are going to be serialized again.

Turnerj avatar Feb 10 '22 01:02 Turnerj

Setting HandleNull does make our converter run however another internal part of S.T.J trips: image

I'm thinking that S.T.J is doing this because a struct can't technically be null instead of setting the struct to its default value.

Turnerj avatar Feb 10 '22 01:02 Turnerj

Tried to mess around with a few settings but doesn't seem like there is anything we can do without trying something drastic like switching Values and OneOrMany to be reference types.

Turnerj avatar Feb 10 '22 01:02 Turnerj