custom serializer for just one property in Json.NET

前端 未结 3 1628
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 10:17

UPDATE Found the issue -- was inheriting from wrong class, needed to be JsonConverter.

I have a class that has a Location property of type System.Da

3条回答
  •  孤街浪徒
    2020-12-05 10:40

    Turns out I just needed to inherit from JsonConverter instead of CustomCreationConverter, and everything else I was trying to change was OK all along.

    I'm still not sure if there's a way to apply the JsonConverter fluently, but there is another way to apply the JsonConverter without referencing Json.NET in your domain/core project or marking up your domain classes with references to a peripheral library:

    var jsonSerializer = new JsonSerializer();
    jsonSerializer.Converters.Add(new DbGeographyConverter());
    jsonSerializer.Serialize(jsonWriter, place);
    

提交回复
热议问题