You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would really like to be able to decorate a property in my class with the converter. For example: [JsonConverter(typeof(GeometryConverter))] public Geometry Location { get; set; }
The converter I'd like to use is "StjGeometryConverter", but it is only available internally or via a factory ("GeoJsonConverterFactory").
Is there a way to use that converter in an attribute, even if it is only exposed by a factory?
Alternatively, is there a reason that converter isn't public?
The text was updated successfully, but these errors were encountered:
Is there a way to use that converter in an attribute, even if it is only exposed by a factory?
The recommended approach is to add an instance of the factory to JsonSerializerOptions.Converters, since that makes it more straightforward to change the constructor call if you eventually find that you need / want to, since you would only theoretically need to touch one place.
However, you should actually be able to use [JsonConverter(typeof(GeoJsonConverterFactory))], since it inherits from JsonConverterFactory, which itself inherits from JsonConverter. I haven't tried this out.
Alternatively, is there a reason that converter isn't public?
For a library like this, in general, I am a proponent of keeping public APIs to a minimum. This means less that we need to document and (in theory) it makes it easier to change implementation details.
In this specific case, it does that, and it also should make it easier to fall into the "pit of success": if we expose just the one converter (in this case, GeoJsonConverterFactory), then you will have access to not only the Geometry parts of the GeoJSON spec, but also the Feature and FeatureCollection parts of it, which let you associate data with each Geometry.
I would really like to be able to decorate a property in my class with the converter. For example:
[JsonConverter(typeof(GeometryConverter))]
public Geometry Location { get; set; }
The converter I'd like to use is "StjGeometryConverter", but it is only available internally or via a factory ("GeoJsonConverterFactory").
Is there a way to use that converter in an attribute, even if it is only exposed by a factory?
Alternatively, is there a reason that converter isn't public?
The text was updated successfully, but these errors were encountered: