Skip to content

Commit

Permalink
feat(net8): add net8 and drop support for net7
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgcubano committed Jan 15, 2024
1 parent 1fedf56 commit f5cf580
Show file tree
Hide file tree
Showing 28 changed files with 435 additions and 440 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ AppyWay geojson model and json serialization converters.

| Package | Latest Stable |
| --- | --- |
| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) |
| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) |
| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-1.3.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) |
| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) |
| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) |
| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-1.4.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) |


## Contribute
Expand Down
6 changes: 3 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#addin nuget:?package=YamlDotNet&version=8.1.2
#addin nuget:?package=YamlDotNet&version=13.7.1
#addin nuget:?package=System.Xml.XDocument&version=4.3.0
#addin nuget:?package=Cake.MinVer&version=2.0.0
#addin nuget:?package=Cake.Yaml&version=3.1.1
#addin nuget:?package=Cake.MinVer&version=3.0.0
#addin nuget:?package=Cake.Yaml&version=6.0.0

#load "./functions.cake"

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"projects": [ "src" ],
"sdk": {
"version": "6.0.300",
"version": "8.0.100",
"rollForward": "latestPatch"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 19 additions & 20 deletions src/Appy.Spatial.GeoJSON.Newtonsoft/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using Newtonsoft.Json;

namespace Appy.Spatial.GeoJSON.Newtonsoft
namespace Appy.Spatial.GeoJSON.Newtonsoft;

public static class Extensions
{
public static class Extensions
public static JsonSerializerSettings UseGeoJsonConverters(this JsonSerializerSettings options)
{
public static JsonSerializerSettings UseGeoJsonConverters(this JsonSerializerSettings options)
{
options.Converters.Add(new FeatureConverter());
options.Converters.Add(new GeometryConverter());
return options;
}
options.Converters.Add(new FeatureConverter());
options.Converters.Add(new GeometryConverter());
return options;
}

internal static T PopulateObject<T>(this JsonSerializer serializer, JsonReader jsonReader, T target)
{
serializer.Populate(jsonReader, target);
internal static T PopulateObject<T>(this JsonSerializer serializer, JsonReader jsonReader, T target)
{
serializer.Populate(jsonReader, target);

if (!serializer.CheckAdditionalContent)
return target;
if (!serializer.CheckAdditionalContent)
return target;

while (jsonReader.Read())
while (jsonReader.Read())
{
if (jsonReader.TokenType != JsonToken.Comment)
{
if (jsonReader.TokenType != JsonToken.Comment)
{
throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
}
throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
}

return target;
}

return target;
}
}
63 changes: 31 additions & 32 deletions src/Appy.Spatial.GeoJSON.Newtonsoft/FeatureConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,46 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Appy.Spatial.GeoJSON.Newtonsoft
namespace Appy.Spatial.GeoJSON.Newtonsoft;

public class FeatureConverter : JsonConverter
{
public class FeatureConverter : JsonConverter
{
public override bool CanWrite => false;
public override bool CanWrite => false;

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);

if (token is not JObject obj)
return null;
if (token is not JObject obj)
return null;

var geometryToken = obj.GetValue("geometry", StringComparison.OrdinalIgnoreCase);
var geometryToken = obj.GetValue("geometry", StringComparison.OrdinalIgnoreCase);

if (!geometryToken!.HasValues)
return FeatureOf<Geometry>(obj, serializer);
if (!geometryToken!.HasValues)
return FeatureOf<Geometry>(obj, serializer);

var geometryType = (geometryToken as JObject)?.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value<string>();
var geometryType = (geometryToken as JObject)?.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value<string>();

return geometryType switch
{
GeoType.GeometryCollection => FeatureOf<GeometryCollection>(obj, serializer),
GeoType.Polygon => FeatureOf<Polygon>(obj, serializer),
GeoType.LineString => FeatureOf<LineString>(obj, serializer),
GeoType.MultiLineString => FeatureOf<MultiLineString>(obj, serializer),
GeoType.MultiPolygon => FeatureOf<MultiPolygon>(obj, serializer),
GeoType.Point => FeatureOf<Point>(obj, serializer),
_ => throw new JsonException($"Unsupported geometry type: {geometryType}")
};
}
return geometryType switch
{
GeoType.GeometryCollection => FeatureOf<GeometryCollection>(obj, serializer),
GeoType.Polygon => FeatureOf<Polygon>(obj, serializer),
GeoType.LineString => FeatureOf<LineString>(obj, serializer),
GeoType.MultiLineString => FeatureOf<MultiLineString>(obj, serializer),
GeoType.MultiPolygon => FeatureOf<MultiPolygon>(obj, serializer),
GeoType.Point => FeatureOf<Point>(obj, serializer),
_ => throw new JsonException($"Unsupported geometry type: {geometryType}")
};
}

public override bool CanConvert(Type objectType) =>
typeof(Feature) == objectType;
public override bool CanConvert(Type objectType) =>
typeof(Feature) == objectType;

static Feature<T> FeatureOf<T>(JToken input, JsonSerializer serializer) where T : Geometry
{
using var jsonReader = input.CreateReader();
return serializer.PopulateObject(jsonReader, new Feature<T>());
}
static Feature<T> FeatureOf<T>(JToken input, JsonSerializer serializer) where T : Geometry
{
using var jsonReader = input.CreateReader();
return serializer.PopulateObject(jsonReader, new Feature<T>());
}
}
57 changes: 28 additions & 29 deletions src/Appy.Spatial.GeoJSON.Newtonsoft/GeometryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Appy.Spatial.GeoJSON.Newtonsoft
namespace Appy.Spatial.GeoJSON.Newtonsoft;

public class GeometryConverter : JsonConverter
{
public class GeometryConverter : JsonConverter
{
public override bool CanWrite => false;
public override bool CanWrite => false;

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);

if (token is not JObject obj)
return null;
if (token is not JObject obj)
return null;

var geometryType = obj.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value<string>();
var geometryType = obj.GetValue("type", StringComparison.OrdinalIgnoreCase)?.Value<string>();

return geometryType switch
{
GeoType.GeometryCollection => GeometryAs<GeometryCollection>(obj, serializer),
GeoType.Polygon => GeometryAs<Polygon>(obj, serializer),
GeoType.LineString => GeometryAs<LineString>(obj, serializer),
GeoType.MultiLineString => GeometryAs<MultiLineString>(obj, serializer),
GeoType.MultiPolygon => GeometryAs<MultiPolygon>(obj, serializer),
GeoType.Point => GeometryAs<Point>(obj, serializer),
_ => throw new JsonException($"Unsupported geometry type {geometryType}")
};
}
return geometryType switch
{
GeoType.GeometryCollection => GeometryAs<GeometryCollection>(obj, serializer),
GeoType.Polygon => GeometryAs<Polygon>(obj, serializer),
GeoType.LineString => GeometryAs<LineString>(obj, serializer),
GeoType.MultiLineString => GeometryAs<MultiLineString>(obj, serializer),
GeoType.MultiPolygon => GeometryAs<MultiPolygon>(obj, serializer),
GeoType.Point => GeometryAs<Point>(obj, serializer),
_ => throw new JsonException($"Unsupported geometry type {geometryType}")
};
}

public override bool CanConvert(Type objectType) =>
typeof(Geometry) == objectType;
public override bool CanConvert(Type objectType) =>
typeof(Geometry) == objectType;

static T GeometryAs<T>(JToken input, JsonSerializer serializer) where T : new()
{
using var jsonReader = input.CreateReader();
return serializer.PopulateObject(jsonReader, new T());
}
static T GeometryAs<T>(JToken input, JsonSerializer serializer) where T : new()
{
using var jsonReader = input.CreateReader();
return serializer.PopulateObject(jsonReader, new T());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -13,16 +13,8 @@
<ProjectReference Include="..\Appy.Spatial.GeoJSON\Appy.Spatial.GeoJSON.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Json" Version="4.6.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Json" Version="6.0.0" />
<ItemGroup>
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 7 additions & 8 deletions src/Appy.Spatial.GeoJSON.TextJson/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.Text.Json;

namespace Appy.Spatial.GeoJSON.TextJson
namespace Appy.Spatial.GeoJSON.TextJson;

public static class Extensions
{
public static class Extensions
public static JsonSerializerOptions UseGeoJsonConverters(this JsonSerializerOptions options)
{
public static JsonSerializerOptions UseGeoJsonConverters(this JsonSerializerOptions options)
{
options.Converters.Add(new FeatureConverter());
options.Converters.Add(new GeometryConverter());
return options;
}
options.Converters.Add(new FeatureConverter());
options.Converters.Add(new GeometryConverter());
return options;
}
}
Loading

0 comments on commit f5cf580

Please sign in to comment.