✅ Newtonsoft serializing returns nothing with custom converter
So I have a custom
JsonConverter
from newtonsoft that is supposed to replace object properties that are a specific type. For context, I'm looking for a type called IOptional
that has properties HasValue
and Value
only if HasValue is true. If HasValue is true, the converter is supposed to replace the json property with Value
. Otherwise, it replaces to null.
I have this
So just to be clear, any other token types works fine along with any objects that don't have IOptional
properties. But when I try this with types that do, serialization returns nothing. Not sure if im incorrectly writing to the jsonwriter, but its been annoying for a few days6 Replies
Additionally, I can replicate this with a fiddle
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
You look for properties assignable to
IOptional
but the Optional
class doesn't implement that interface.
The design pattern also seems curious and perhaps outdated with nullable reference types. I'd love to know more about the reasoningThe
IOptional
interface is from an entire different library and the one im replicating is just a quick example
also in the fiddle, the type im checking for is the Optional
class I have thereso in my project, I do have objects im testing that actually have properties with this interface
GitHub
Remora.Rest/Remora.Rest.Core/IOptional.cs at main · Remora/Remora.R...
Reusable tooling for interacting with JSON-driven REST APIs - Remora/Remora.Rest
Bump up
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.