I am attempting to deserialize a geojson FeatureCollection
. The API I am querying returns this feature collection with additional properties on the type. The properties are used for cursor-based pagination.
The FeatureCollection
is deserialized using ‘NetTopologySuite.IO.GeoJsonConverterFactory’. That works great for the first page of results.
The problem is that the NTS (NetTopologySuite) FeatureCollection
class does not have these pagination properties and they are thus not deserialized.
The API in question:
https://api.pdok.nl/lv/bgt/ogc/v1/api
Some sample containing the “links” property that has the required pagination link.
https://api.pdok.nl/lv/bgt/ogc/v1/collections/pand/items?f=json
I’ve tried deserializing the api response json twice. Once as a feature collection, once as a custom poco containing only the additional properties.
public class Link
{
public string Rel { get; set; }
public string Type { get; set; }
public string Title { get; set; }
public string Href { get; set; }
}
public class FeatureCollectionResponse
{
public Link[] Links { get; set; }
public int NumberReturned { get; set; }
}
...
var json = await response.Content.ReadAsStringAsync();
var featureCollection = JsonSerializer.Deserialize<FeatureCollection>(json, _serializerOptions);
meta = JsonSerializer.Deserialize<FeatureCollectionResponse>(json, _serializerOptions);
The feature collection is properly filled but the properties on the meta information are all null.
What is the right way extract these additional properties? A wrapper class perhaps. But what would that look like?
Can I create a JsonConverter for the FeatureCollection
that handles these additions and delegate the rest of the type to the NTS deserializer?