Closed mlorbetske closed 1 week ago
PR available in https://github.com/JamesNK/Newtonsoft.Json/pull/2877
It's debatable whether this is a bug requiring a fix or whether this is intentional behavior, and since i am not the author nor a maintainer of Newtonsoft.Json i leave it to them to evaluate this situation.
However, as a side note and unrelated to the issue your report is about, please note that doing writer.WriteRawValue(x.D.ToString());
in your WriteJson method is wrong, as it can lead to invalid json. Transforming the decimal to a string using the parameterless ToString() method uses the current culture. If the current culture uses a decimal comma, writing x.D.ToString()
as raw value will screw up the resulting json.
@elgonzo thanks for the response. yep, the converter was just an example, not intended to be production-ready code.
Source/destination types and Repro Steps
Source/destination JSON
Expected behavior
The
ReadAsString()
call in the JsonConverter above should have returned the text captured in the Raw type tokenActual behavior
Newtonsoft.Json.JsonReaderException: 'Error reading string. Unexpected token: Raw. Path 'D'.'
at Newtonsoft.Json.JsonReader.ReadAsString() in /_/Src/Newtonsoft.Json/JsonReader.cs:line 507