79486155

Date: 2025-03-05 10:32:41
Score: 1
Natty:
Report link

@MindSwipe triggered the answer.

I needed to rewrite the Program.cs to:

var subclass = new Subclass
{
    NaN = double.NaN // for a value like 2.3 it works without any problems
};

var serializeOptions = new JsonSerializerOptions
{
    NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
    //Converters = { new SubConvertor() }
};
serializeOptions.Converters.Add(new SubConvertor()); //do it like this ... even if right now I do not understand why it works.
var jsonString = JsonSerializer.Serialize(subclass, serializeOptions);
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MindSwipe
  • Self-answer (0.5):
Posted by: Liviu Sosu