✅ JSON serializing Optional type throws an exception(?)
Newtonsoft.Json.JsonWriterException: Token PropertyName in state Property would result in an invalid JSON object. Path ''.
Here's my JsonConverter:
I'm not quite sure what's going on here as it's difficult for me to debug what JSON is being serialized by the Serialize call or what Json.NET is trying to validate later on. Serializing to a StringBuilder instead of the writer yields a simple string property is being serialized, and yet this exception is being thrown. Google was very unhelpful as one of the only results for this exact error message was for something completely different, and the exception message doesn't really yield any clues.
I found out about ITraceWriter, and here's what it was able to output:
1 Reply
I figured out the issue, I'm not serializing the property value, but the property name is still getting serialized. I haven't solved that problem, but at least I know the cause now