We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm serializing an array of MyInfo objects using the following converter, with JSON serializer formatting set to indented:
MyInfo
class TestConverter : JsonConverter<MyInfo> { public override void WriteJson(JsonWriter writer, MyInfo value, JsonSerializer serializer) { var subSerializer = new JsonSerializer { Formatting = Formatting.None, }; subSerializer.Serialize(writer, new Dictionary<string, string> { { "Name", value.Name } }); } public override MyInfo ReadJson(JsonReader reader, Type objectType, MyInfo existingValue, bool hasExistingValue, JsonSerializer serializer) { throw new NotSupportedException(); } } class MyInfo { public string Name; }
I expected that it would use the nested serializer to serialize the values of the objects only, so the result would look like this:
[ {"Name":"SomeName1"}, {"Name":"SomeName2"} ]
However, it looks like this:
[{"Name":"SomeName1"},{"Name":"SomeName2"}]
What am I missing?
The text was updated successfully, but these errors were encountered:
PS when I do conversion like this, it works as expected:
var text = JsonConvert.SerializeObject(new Dictionary<string, string> { { "Name", value.Name } }); writer.WriteRawValue(text);
I wonder why the code with the nested serializer doesn't?
Sorry, something went wrong.
Hi @codemonkey493 , You can use Formatting = Formatting.Indented to indent the formatting of the serialized objects.
Formatting = Formatting.Indented
No branches or pull requests
Source/destination types
I'm serializing an array of
MyInfo
objects using the following converter, with JSON serializer formatting set to indented:Expected behavior
I expected that it would use the nested serializer to serialize the values of the objects only, so the result would look like this:
Actual behavior
However, it looks like this:
What am I missing?
The text was updated successfully, but these errors were encountered: