UPDATE Found a problem - inherited from the wrong class, must be JsonConverter.
I have a class that has a Location property of type System.Data.Entity.Spatial.DbGeography. The Json.NET serializer, by default, displays JSON text as follows:
... "PlaceType": 0, "Location": { "Geography": { "CoordinateSystemId": 4326, "WellKnownText": "POINT (-88.00000 44.00000)" } }, "AddedDT": null, ...
I want it to look like this:
... "PlaceType": 0, "Location": [-88.00000,44.00000], "AddedDT": null, ...
... so it seems to me what I should do is to override any converter currently used for the DbGeography type.
The examples I've seen so far that use CustomCreationConverters and ContractResolvers seem to relate to how you replace the serializer for the serializable main class, and not for the type that is only a property of this class. Examples that include annotating a class that is being redefined do not work for me because I do not define DbGeography in my code, and this is actually a private class because it does not have a constructor and can only be created by internal factory methods.
Is there a way to apply JsonConverter to a type freely? If so, what would the converter look like? Should I just override the WriteJson () method?
source share