Open SebastianStehle opened 2 years ago
Can you give me an example of what can't be done without this converter so I can understand the issue a little better?
Lets say, I have the following request definition:
class CreateGeometry
{
[Required]
public GeoJsonObject Geometry {get; set; }
}
So the user can either give in a point or circle or polygon or whatever.
I don't see how this is possible at the moment and I also tested it and got an error.
What you want works by using the geometry interface.
IGeometryObject
Oh, sorry ... have not seen that. Why is there both a interface and a abstract class?
I sadly do not know, since i have not been a part of the initial implementation of the library, i just converted it to system.text.json, but i guess the abstract class exists to share common properties to all of the geometry object types. Maybe it should be internal, since it makes no sense to use it externally.
Is there a way to get this to work with any GeoJson object, not only geometry types (i.e. also Feature and Feature Collection). Using IGeoJsonObject does not seem to work?
I would like to serialize any type of geoJson object, but this does not work:
>>> System.Text.Json.JsonSerializer.Serialize((GeoJSON.Text.IGeoJSONObject)source.Data)
"{\"type\":8,\"crs\":null,\"bbox\":null}"
I can properly serialize it as a feature collection, but this is not polymorphic:
>>> System.Text.Json.JsonSerializer.Serialize((FeatureCollection)source.Data)
"{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[90,50],[25,0]]},\"properties\":{}}]}"
Using IGeometryObject is not an option, because not all GeoJson objects are geometry objects:
>>> System.Text.Json.JsonSerializer.Serialize((IGeometryObject)source.Data)
'System.Text.Json.JsonSerializer.Serialize((IGeometryObject)source.Data)' threw an exception of type 'System.InvalidCastException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467262
HelpLink: null
InnerException: null
Message: "Specified cast is not valid."
Source: "006cbf0666ad4386b97cab13a906b566"
StackTrace: " at <>x.<>m0(<OnLoad>d__4 <>4__this)"
TargetSite: {System.String <>m0(<OnLoad>d__4)}
ditto. need to parse GeoJson data without knowing beforehand whether it is a geometry or feature or feature collection etc. how ?
It looks like this is within reach, it just requires another converter for the top level IGeoJSONObject
which can switch internally on GeoJSONObjectType
, similar to how the polymorphic IGeometryObject
converter works:
Have you not handled polymorphism? I do not see converters for GeoJSONObject ot the interfaces.