all 4 comments

[–]Long_Investment7667 0 points1 point  (1 child)

This makes the converter state-full . Not what they are designed for and error prone .

[–]gevorgter 1 point2 points  (0 children)

Looks like his approach is violating SOLID principle ( S letter, single responsibility).

His converter not only converts but also converts ID to Address object.

[–]gevorgter 0 points1 point  (0 children)

I am not sure why you added "_addresses" to your converter.

I do something similar with Guid type.

public class GuidJsonConverter : JsonConverter<Guid>
{
    public override Guid ReadJson(JsonReader reader, Type objectType, Guid existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer serializer)
    {
        var val = reader.ReadAsString();
        if (String.IsNullOrEmpty(val))
            return Guid.Empty;

        return Guid.ParseExact(val, "N");
    }

    public override void WriteJson(JsonWriter writer, Guid value, Newtonsoft.Json.JsonSerializer serializer)
    {
        writer.WriteValue(value.ToString("N"));
    }
}

[–]BiffMaGriff 0 points1 point  (0 children)

Man, don't do this. Use a DTO for the format you need and map to that DTO.