I created a custom JsonConverter for a specific type.
public class FooNewtonsoftConverter : JsonConverter<Foo>{
public override void WriteJson(JsonWriter writer, Foo value, JsonSerializer serializer)
{
writer.WriteStartObject();
// Should it be serialized as "Id" or "id"?
writer.WritePropertyName("id");
writer.WriteValue(value.Id);
writer.WriteEndObject();
}
}
It is possible to customize the JsonSerializer to use a different naming strategy, such as CamelCasePropertyNamesContractResolver
or changing the NamingStrategy
to a CamelCaseNamingStrategy
.
You can also decorate the property with a JsonProperty
to change the name.
How can I resolve the right property names for the properties I'm serializing?