From a086e93946e50e6f5ffe8cd57c346b958adecbec Mon Sep 17 00:00:00 2001 From: Martin Carpentier Date: Wed, 15 Dec 2021 20:50:49 +0100 Subject: [PATCH 1/6] Changed some naming of folders in project. Also changed the path in the SLN file to point to the new route after folder renaming --- .../CoordinateReferenceSystem/DefaultCrsTests.cs | 0 .../CoordinateReferenceSystem/LinkedCRSTests.cs | 0 .../CoordinateReferenceSystem/NamedCrsTests.cs | 0 .../CoordinateReferenceSystem/UnspecifiedCRSTests.cs | 0 .../Feature/FeatureCollectionTests.cs | 0 .../Feature/FeatureCollectionTests_Can_Deserialize.json | 0 .../Feature/FeatureTests.cs | 0 .../Feature/FeatureTests_Can_Deserialize_Point_Feature.json | 0 .../FeatureTests_Can_Serialize_Dictionary_Subclass.json | 0 .../FeatureTests_Can_Serialize_LineString_Feature.json | 0 .../FeatureTests_Can_Serialize_MultiLineString_Feature.json | 0 .../FeatureTests_Can_Serialize_MultiPolygon_Feature.json | 0 .../Feature/FeatureTests_Can_Serialize_Point_Feature.json | 0 .../Feature/FeatureTests_Can_Serialize_Polygon_Feature.json | 0 .../Feature/GenericFeatureTests.cs | 0 ...enericFeatureTests_Can_Deserialize_LineString_Feature.json | 0 .../GenericFeatureTests_Can_Deserialize_Point_Feature.json | 0 ...nericFeatureTests_Can_Deserialize_Typed_Point_Feature.json | 0 ...GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json | 0 .../Feature/TestFeatureEnum.cs | 0 .../Feature/TestFeatureProperty.cs | 0 .../Feature/TestFeaturePropertyDictionary.cs | 0 .../GeoJSON.Text.Tests.csproj | 0 .../Geometry/GeometryTests.cs | 0 .../Geometry/LineStringTests.cs | 0 .../Geometry/LineStringTests_Can_Deserialize.json | 0 .../Geometry/LineStringTests_Can_Serialize.json | 0 .../Geometry/MultiLineStringTests.cs | 0 .../Geometry/MultiLineStringTests_Can_Deserialize.json | 0 .../Geometry/MultiLineStringTests_Can_Serialize.json | 0 .../Geometry/MultiPointTests.cs | 0 .../Geometry/MultiPointTests_Can_Deserialize.json | 0 .../Geometry/MultiPointTests_Can_Serialize.json | 0 .../Geometry/MultiPolygonTests.cs | 0 .../Geometry/MultiPolygonTests_Can_Deserialize.json | 0 .../Geometry/MultiPolygonTests_Can_Serialize.json | 0 .../Geometry/PointTests.cs | 0 .../Geometry/PolygonTests.cs | 0 .../Geometry/PolygonTests_Can_Deserialize.json | 0 ...onTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json | 0 .../Geometry/PolygonTests_Can_Serialize.json | 0 src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/JsonAssert.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Settings.StyleCop | 0 src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/TestBase.cs | 0 src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/app.config | 0 src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/packages.config | 0 src/{GeoJSON.Net.sln => GeoJSON.Text.sln} | 4 ++-- src/{GeoJSON.Net => GeoJSON.Text}/Converters/CrsConverter.cs | 0 .../Converters/GeoJsonConverter.cs | 0 .../Converters/GeometryConverter.cs | 0 .../Converters/LineStringEnumerableConverter.cs | 0 .../Converters/PointEnumerableConverter.cs | 0 .../Converters/PolygonEnumerableConverter.cs | 0 .../Converters/PositionConverter.cs | 0 .../Converters/PositionEnumerableConverter.cs | 0 .../Converters/TypeExtensions.cs | 0 .../CoordinateReferenceSystem/CRSBase.cs | 0 .../CoordinateReferenceSystem/CRSType.cs | 0 .../CoordinateReferenceSystem/DefaultCRS.cs | 0 .../CoordinateReferenceSystem/ICRSObject.cs | 0 .../CoordinateReferenceSystem/LinkedCRS.cs | 0 .../CoordinateReferenceSystem/NamedCRS.cs | 0 .../CoordinateReferenceSystem/UnspecifiedCRS.cs | 0 .../DoubleTenDecimalPlaceComparer.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Feature/Feature.cs | 0 .../Feature/FeatureCollection.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/GeoJSON.Text.csproj | 0 src/{GeoJSON.Net => GeoJSON.Text}/GeoJSONObject.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/GeoJSONObjectType.cs | 0 .../Geometry/GeometryCollection.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/IGeometryObject.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/IPosition.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/LineString.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiLineString.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiPoint.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiPolygon.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Point.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Polygon.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Position.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/IGeoJSONObject.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/PositionExtensions.cs | 0 src/{GeoJSON.Net => GeoJSON.Text}/Settings.StyleCop | 0 83 files changed, 2 insertions(+), 2 deletions(-) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/CoordinateReferenceSystem/DefaultCrsTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/CoordinateReferenceSystem/LinkedCRSTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/CoordinateReferenceSystem/NamedCrsTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/CoordinateReferenceSystem/UnspecifiedCRSTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureCollectionTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureCollectionTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Deserialize_Point_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_LineString_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_MultiLineString_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_Point_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/FeatureTests_Can_Serialize_Polygon_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/GenericFeatureTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/GenericFeatureTests_Can_Deserialize_LineString_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/GenericFeatureTests_Can_Deserialize_Point_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/GenericFeatureTests_Can_Deserialize_Typed_Point_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/TestFeatureEnum.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/TestFeatureProperty.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Feature/TestFeaturePropertyDictionary.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/GeoJSON.Text.Tests.csproj (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/GeometryTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/LineStringTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/LineStringTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/LineStringTests_Can_Serialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiLineStringTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiLineStringTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiLineStringTests_Can_Serialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPointTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPointTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPointTests_Can_Serialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPolygonTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPolygonTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/MultiPolygonTests_Can_Serialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/PointTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/PolygonTests.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/PolygonTests_Can_Deserialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/PolygonTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Geometry/PolygonTests_Can_Serialize.json (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/JsonAssert.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Properties/AssemblyInfo.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/Settings.StyleCop (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/TestBase.cs (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/app.config (100%) rename src/{GeoJSON.Net.Tests => GeoJSON.Text.Tests}/packages.config (100%) rename src/{GeoJSON.Net.sln => GeoJSON.Text.sln} (90%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/CrsConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/GeoJsonConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/GeometryConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/LineStringEnumerableConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/PointEnumerableConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/PolygonEnumerableConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/PositionConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/PositionEnumerableConverter.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Converters/TypeExtensions.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/CRSBase.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/CRSType.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/DefaultCRS.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/ICRSObject.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/LinkedCRS.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/NamedCRS.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/CoordinateReferenceSystem/UnspecifiedCRS.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/DoubleTenDecimalPlaceComparer.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Feature/Feature.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Feature/FeatureCollection.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/GeoJSON.Text.csproj (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/GeoJSONObject.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/GeoJSONObjectType.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/GeometryCollection.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/IGeometryObject.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/IPosition.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/LineString.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiLineString.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiPoint.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/MultiPolygon.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Point.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Polygon.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Geometry/Position.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/IGeoJSONObject.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/PositionExtensions.cs (100%) rename src/{GeoJSON.Net => GeoJSON.Text}/Settings.StyleCop (100%) diff --git a/src/GeoJSON.Net.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs rename to src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs diff --git a/src/GeoJSON.Net.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs rename to src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs diff --git a/src/GeoJSON.Net.Tests/CoordinateReferenceSystem/NamedCrsTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/CoordinateReferenceSystem/NamedCrsTests.cs rename to src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs diff --git a/src/GeoJSON.Net.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs rename to src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureCollectionTests.cs b/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureCollectionTests.cs rename to src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureCollectionTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureCollectionTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs b/src/GeoJSON.Text.Tests/Feature/FeatureTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests.cs rename to src/GeoJSON.Text.Tests/Feature/FeatureTests.cs diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Deserialize_Point_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Point_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Deserialize_Point_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_MultiLineString_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiLineString_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_MultiLineString_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiLineString_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Polygon_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Polygon_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Serialize_Polygon_Feature.json rename to src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Polygon_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/GenericFeatureTests.cs b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/GenericFeatureTests.cs rename to src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs diff --git a/src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_LineString_Feature.json b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_LineString_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_LineString_Feature.json rename to src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_LineString_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_Point_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_Point_Feature.json rename to src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_Point_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_Typed_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_Typed_Point_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Deserialize_Typed_Point_Feature.json rename to src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Deserialize_Typed_Point_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json rename to src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json diff --git a/src/GeoJSON.Net.Tests/Feature/TestFeatureEnum.cs b/src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/TestFeatureEnum.cs rename to src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs diff --git a/src/GeoJSON.Net.Tests/Feature/TestFeatureProperty.cs b/src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/TestFeatureProperty.cs rename to src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs diff --git a/src/GeoJSON.Net.Tests/Feature/TestFeaturePropertyDictionary.cs b/src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Feature/TestFeaturePropertyDictionary.cs rename to src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs diff --git a/src/GeoJSON.Net.Tests/GeoJSON.Text.Tests.csproj b/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj similarity index 100% rename from src/GeoJSON.Net.Tests/GeoJSON.Text.Tests.csproj rename to src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj diff --git a/src/GeoJSON.Net.Tests/Geometry/GeometryTests.cs b/src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/GeometryTests.cs rename to src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/LineStringTests.cs b/src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/LineStringTests.cs rename to src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/LineStringTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Geometry/LineStringTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/LineStringTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Geometry/LineStringTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/LineStringTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/LineStringTests_Can_Serialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/LineStringTests_Can_Serialize.json rename to src/GeoJSON.Text.Tests/Geometry/LineStringTests_Can_Serialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests.cs rename to src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests_Can_Serialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiLineStringTests_Can_Serialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests_Can_Serialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPointTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPointTests.cs rename to src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPointTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiPointTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPointTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiPointTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPointTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiPointTests_Can_Serialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPointTests_Can_Serialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiPointTests_Can_Serialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests.cs rename to src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/MultiPolygonTests_Can_Serialize.json rename to src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/PointTests.cs b/src/GeoJSON.Text.Tests/Geometry/PointTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/PointTests.cs rename to src/GeoJSON.Text.Tests/Geometry/PointTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/PolygonTests.cs b/src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/PolygonTests.cs rename to src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs diff --git a/src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Deserialize.json b/src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Deserialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Deserialize.json rename to src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Deserialize.json diff --git a/src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json b/src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json rename to src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Deserialize_With_Exterior_And_Inner_Rings.json diff --git a/src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Serialize.json similarity index 100% rename from src/GeoJSON.Net.Tests/Geometry/PolygonTests_Can_Serialize.json rename to src/GeoJSON.Text.Tests/Geometry/PolygonTests_Can_Serialize.json diff --git a/src/GeoJSON.Net.Tests/JsonAssert.cs b/src/GeoJSON.Text.Tests/JsonAssert.cs similarity index 100% rename from src/GeoJSON.Net.Tests/JsonAssert.cs rename to src/GeoJSON.Text.Tests/JsonAssert.cs diff --git a/src/GeoJSON.Net.Tests/Properties/AssemblyInfo.cs b/src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs similarity index 100% rename from src/GeoJSON.Net.Tests/Properties/AssemblyInfo.cs rename to src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs diff --git a/src/GeoJSON.Net.Tests/Settings.StyleCop b/src/GeoJSON.Text.Tests/Settings.StyleCop similarity index 100% rename from src/GeoJSON.Net.Tests/Settings.StyleCop rename to src/GeoJSON.Text.Tests/Settings.StyleCop diff --git a/src/GeoJSON.Net.Tests/TestBase.cs b/src/GeoJSON.Text.Tests/TestBase.cs similarity index 100% rename from src/GeoJSON.Net.Tests/TestBase.cs rename to src/GeoJSON.Text.Tests/TestBase.cs diff --git a/src/GeoJSON.Net.Tests/app.config b/src/GeoJSON.Text.Tests/app.config similarity index 100% rename from src/GeoJSON.Net.Tests/app.config rename to src/GeoJSON.Text.Tests/app.config diff --git a/src/GeoJSON.Net.Tests/packages.config b/src/GeoJSON.Text.Tests/packages.config similarity index 100% rename from src/GeoJSON.Net.Tests/packages.config rename to src/GeoJSON.Text.Tests/packages.config diff --git a/src/GeoJSON.Net.sln b/src/GeoJSON.Text.sln similarity index 90% rename from src/GeoJSON.Net.sln rename to src/GeoJSON.Text.sln index e311bbe..0ae6733 100644 --- a/src/GeoJSON.Net.sln +++ b/src/GeoJSON.Text.sln @@ -10,9 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\README.md = ..\README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text.Tests", "GeoJSON.Net.Tests\GeoJSON.Text.Tests.csproj", "{6C93B314-9208-4684-B873-172F7EC81689}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text.Tests", "GeoJSON.Text.Tests\GeoJSON.Text.Tests.csproj", "{6C93B314-9208-4684-B873-172F7EC81689}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text", "GeoJSON.Net\GeoJSON.Text.csproj", "{8AF7C40E-E8C7-425F-A8B1-A4B7E74D3CA9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text", "GeoJSON.Text\GeoJSON.Text.csproj", "{8AF7C40E-E8C7-425F-A8B1-A4B7E74D3CA9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/GeoJSON.Net/Converters/CrsConverter.cs b/src/GeoJSON.Text/Converters/CrsConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/CrsConverter.cs rename to src/GeoJSON.Text/Converters/CrsConverter.cs diff --git a/src/GeoJSON.Net/Converters/GeoJsonConverter.cs b/src/GeoJSON.Text/Converters/GeoJsonConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/GeoJsonConverter.cs rename to src/GeoJSON.Text/Converters/GeoJsonConverter.cs diff --git a/src/GeoJSON.Net/Converters/GeometryConverter.cs b/src/GeoJSON.Text/Converters/GeometryConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/GeometryConverter.cs rename to src/GeoJSON.Text/Converters/GeometryConverter.cs diff --git a/src/GeoJSON.Net/Converters/LineStringEnumerableConverter.cs b/src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/LineStringEnumerableConverter.cs rename to src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs diff --git a/src/GeoJSON.Net/Converters/PointEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PointEnumerableConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/PointEnumerableConverter.cs rename to src/GeoJSON.Text/Converters/PointEnumerableConverter.cs diff --git a/src/GeoJSON.Net/Converters/PolygonEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/PolygonEnumerableConverter.cs rename to src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs diff --git a/src/GeoJSON.Net/Converters/PositionConverter.cs b/src/GeoJSON.Text/Converters/PositionConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/PositionConverter.cs rename to src/GeoJSON.Text/Converters/PositionConverter.cs diff --git a/src/GeoJSON.Net/Converters/PositionEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs similarity index 100% rename from src/GeoJSON.Net/Converters/PositionEnumerableConverter.cs rename to src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs diff --git a/src/GeoJSON.Net/Converters/TypeExtensions.cs b/src/GeoJSON.Text/Converters/TypeExtensions.cs similarity index 100% rename from src/GeoJSON.Net/Converters/TypeExtensions.cs rename to src/GeoJSON.Text/Converters/TypeExtensions.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/CRSBase.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/CRSBase.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/CRSType.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/CRSType.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/DefaultCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/DefaultCRS.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/ICRSObject.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/ICRSObject.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/LinkedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/LinkedCRS.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/NamedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/NamedCRS.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs diff --git a/src/GeoJSON.Net/CoordinateReferenceSystem/UnspecifiedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs similarity index 100% rename from src/GeoJSON.Net/CoordinateReferenceSystem/UnspecifiedCRS.cs rename to src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs diff --git a/src/GeoJSON.Net/DoubleTenDecimalPlaceComparer.cs b/src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs similarity index 100% rename from src/GeoJSON.Net/DoubleTenDecimalPlaceComparer.cs rename to src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs diff --git a/src/GeoJSON.Net/Feature/Feature.cs b/src/GeoJSON.Text/Feature/Feature.cs similarity index 100% rename from src/GeoJSON.Net/Feature/Feature.cs rename to src/GeoJSON.Text/Feature/Feature.cs diff --git a/src/GeoJSON.Net/Feature/FeatureCollection.cs b/src/GeoJSON.Text/Feature/FeatureCollection.cs similarity index 100% rename from src/GeoJSON.Net/Feature/FeatureCollection.cs rename to src/GeoJSON.Text/Feature/FeatureCollection.cs diff --git a/src/GeoJSON.Net/GeoJSON.Text.csproj b/src/GeoJSON.Text/GeoJSON.Text.csproj similarity index 100% rename from src/GeoJSON.Net/GeoJSON.Text.csproj rename to src/GeoJSON.Text/GeoJSON.Text.csproj diff --git a/src/GeoJSON.Net/GeoJSONObject.cs b/src/GeoJSON.Text/GeoJSONObject.cs similarity index 100% rename from src/GeoJSON.Net/GeoJSONObject.cs rename to src/GeoJSON.Text/GeoJSONObject.cs diff --git a/src/GeoJSON.Net/GeoJSONObjectType.cs b/src/GeoJSON.Text/GeoJSONObjectType.cs similarity index 100% rename from src/GeoJSON.Net/GeoJSONObjectType.cs rename to src/GeoJSON.Text/GeoJSONObjectType.cs diff --git a/src/GeoJSON.Net/Geometry/GeometryCollection.cs b/src/GeoJSON.Text/Geometry/GeometryCollection.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/GeometryCollection.cs rename to src/GeoJSON.Text/Geometry/GeometryCollection.cs diff --git a/src/GeoJSON.Net/Geometry/IGeometryObject.cs b/src/GeoJSON.Text/Geometry/IGeometryObject.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/IGeometryObject.cs rename to src/GeoJSON.Text/Geometry/IGeometryObject.cs diff --git a/src/GeoJSON.Net/Geometry/IPosition.cs b/src/GeoJSON.Text/Geometry/IPosition.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/IPosition.cs rename to src/GeoJSON.Text/Geometry/IPosition.cs diff --git a/src/GeoJSON.Net/Geometry/LineString.cs b/src/GeoJSON.Text/Geometry/LineString.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/LineString.cs rename to src/GeoJSON.Text/Geometry/LineString.cs diff --git a/src/GeoJSON.Net/Geometry/MultiLineString.cs b/src/GeoJSON.Text/Geometry/MultiLineString.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/MultiLineString.cs rename to src/GeoJSON.Text/Geometry/MultiLineString.cs diff --git a/src/GeoJSON.Net/Geometry/MultiPoint.cs b/src/GeoJSON.Text/Geometry/MultiPoint.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/MultiPoint.cs rename to src/GeoJSON.Text/Geometry/MultiPoint.cs diff --git a/src/GeoJSON.Net/Geometry/MultiPolygon.cs b/src/GeoJSON.Text/Geometry/MultiPolygon.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/MultiPolygon.cs rename to src/GeoJSON.Text/Geometry/MultiPolygon.cs diff --git a/src/GeoJSON.Net/Geometry/Point.cs b/src/GeoJSON.Text/Geometry/Point.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/Point.cs rename to src/GeoJSON.Text/Geometry/Point.cs diff --git a/src/GeoJSON.Net/Geometry/Polygon.cs b/src/GeoJSON.Text/Geometry/Polygon.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/Polygon.cs rename to src/GeoJSON.Text/Geometry/Polygon.cs diff --git a/src/GeoJSON.Net/Geometry/Position.cs b/src/GeoJSON.Text/Geometry/Position.cs similarity index 100% rename from src/GeoJSON.Net/Geometry/Position.cs rename to src/GeoJSON.Text/Geometry/Position.cs diff --git a/src/GeoJSON.Net/IGeoJSONObject.cs b/src/GeoJSON.Text/IGeoJSONObject.cs similarity index 100% rename from src/GeoJSON.Net/IGeoJSONObject.cs rename to src/GeoJSON.Text/IGeoJSONObject.cs diff --git a/src/GeoJSON.Net/PositionExtensions.cs b/src/GeoJSON.Text/PositionExtensions.cs similarity index 100% rename from src/GeoJSON.Net/PositionExtensions.cs rename to src/GeoJSON.Text/PositionExtensions.cs diff --git a/src/GeoJSON.Net/Settings.StyleCop b/src/GeoJSON.Text/Settings.StyleCop similarity index 100% rename from src/GeoJSON.Net/Settings.StyleCop rename to src/GeoJSON.Text/Settings.StyleCop From 3c06947a278950bb8c546167932b4d40e9b45d76 Mon Sep 17 00:00:00 2001 From: Martin Carpentier Date: Thu, 16 Dec 2021 20:52:44 +0100 Subject: [PATCH 2/6] Converted code to support system.text.json Updated the code to support system.text.json, and also updated the tests to run using system.text.json. Issues that needs fixing: Could not make the jsonconstructor work properly, so i updated the properties to be INIT. This does not solve that the classes can be instantiated invalidly, so more work might have to go into solving the jsonconstructors. --- .../DefaultCrsTests.cs | 22 +- .../LinkedCRSTests.cs | 19 +- .../NamedCrsTests.cs | 10 +- .../UnspecifiedCRSTests.cs | 12 +- .../Feature/FeatureCollectionTests.cs | 30 +-- .../Feature/FeatureTests.cs | 119 +++++----- ...sts_Can_Serialize_Dictionary_Subclass.json | 4 +- ...ests_Can_Serialize_LineString_Feature.json | 34 ++- ...ts_Can_Serialize_MultiPolygon_Feature.json | 30 +-- ...tureTests_Can_Serialize_Point_Feature.json | 2 +- .../Feature/GenericFeatureTests.cs | 29 +-- ...sts_Can_Serialize_Typed_Point_Feature.json | 2 +- .../Feature/TestFeatureEnum.cs | 2 +- .../Feature/TestFeatureProperty.cs | 2 +- .../Feature/TestFeaturePropertyDictionary.cs | 2 +- .../GeoJSON.Text.Tests.csproj | 66 +++++- .../Geometry/GeometryTests.cs | 28 ++- .../Geometry/LineStringTests.cs | 14 +- .../Geometry/MultiLineStringTests.cs | 12 +- .../Geometry/MultiPointTests.cs | 12 +- .../Geometry/MultiPolygonTests.cs | 10 +- .../MultiPolygonTests_Can_Serialize.json | 30 +-- src/GeoJSON.Text.Tests/Geometry/PointTests.cs | 20 +- .../Geometry/PolygonTests.cs | 23 +- src/GeoJSON.Text.Tests/JsonAssert.cs | 2 +- .../Properties/AssemblyInfo.cs | 26 -- src/GeoJSON.Text.Tests/Settings.StyleCop | 10 - src/GeoJSON.Text.Tests/TestBase.cs | 22 +- src/GeoJSON.Text.Tests/app.config | 7 - src/GeoJSON.Text.Tests/packages.config | 6 - .../Converters/BoundingBoxConverter.cs | 61 +++++ .../CRSBaseRequiredPropertyConverter.cs | 37 +++ src/GeoJSON.Text/Converters/CrsConverter.cs | 224 +++++++++--------- .../Converters/FeatureConverter.cs | 117 +++++++++ .../Converters/GeoJsonConverter.cs | 133 ----------- .../Converters/GeometryConverter.cs | 125 +++++----- .../Converters/GeometryEnumerableConverter.cs | 93 ++++++++ .../JsonStringEnumEnumMemberConverter.cs | 63 +++++ .../LineStringEnumerableConverter.cs | 78 +++--- .../Converters/PointEnumerableConverter.cs | 75 ++++-- .../Converters/PolygonEnumerableConverter.cs | 80 ++++--- .../Converters/PositionConverter.cs | 46 ++-- .../Converters/PositionEnumerableConverter.cs | 78 +++--- src/GeoJSON.Text/Converters/TypeExtensions.cs | 11 +- .../CoordinateReferenceSystem/CRSBase.cs | 17 +- .../CoordinateReferenceSystem/CRSType.cs | 3 +- .../CoordinateReferenceSystem/DefaultCRS.cs | 2 +- .../CoordinateReferenceSystem/ICRSObject.cs | 2 +- .../CoordinateReferenceSystem/LinkedCRS.cs | 9 +- .../CoordinateReferenceSystem/NamedCRS.cs | 9 +- .../UnspecifiedCRS.cs | 9 +- .../DoubleTenDecimalPlaceComparer.cs | 2 +- src/GeoJSON.Text/Feature/Feature.cs | 161 ++++++++++--- src/GeoJSON.Text/Feature/FeatureCollection.cs | 13 +- src/GeoJSON.Text/GeoJSON.Text.csproj | 2 +- src/GeoJSON.Text/GeoJSONObject.cs | 34 +-- src/GeoJSON.Text/GeoJSONObjectType.cs | 15 +- .../Geometry/GeometryCollection.cs | 15 +- src/GeoJSON.Text/Geometry/IGeometryObject.cs | 10 +- src/GeoJSON.Text/Geometry/IPosition.cs | 4 +- src/GeoJSON.Text/Geometry/LineString.cs | 21 +- src/GeoJSON.Text/Geometry/MultiLineString.cs | 26 +- src/GeoJSON.Text/Geometry/MultiPoint.cs | 26 +- src/GeoJSON.Text/Geometry/MultiPolygon.cs | 16 +- src/GeoJSON.Text/Geometry/Point.cs | 19 +- src/GeoJSON.Text/Geometry/Polygon.cs | 26 +- src/GeoJSON.Text/Geometry/Position.cs | 6 +- src/GeoJSON.Text/IGeoJSONObject.cs | 9 +- src/GeoJSON.Text/PositionExtensions.cs | 4 +- src/GeoJSON.Text/Settings.StyleCop | 2 +- 70 files changed, 1416 insertions(+), 874 deletions(-) delete mode 100644 src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs delete mode 100644 src/GeoJSON.Text.Tests/Settings.StyleCop delete mode 100644 src/GeoJSON.Text.Tests/app.config delete mode 100644 src/GeoJSON.Text.Tests/packages.config create mode 100644 src/GeoJSON.Text/Converters/BoundingBoxConverter.cs create mode 100644 src/GeoJSON.Text/Converters/CRSBaseRequiredPropertyConverter.cs create mode 100644 src/GeoJSON.Text/Converters/FeatureConverter.cs delete mode 100644 src/GeoJSON.Text/Converters/GeoJsonConverter.cs create mode 100644 src/GeoJSON.Text/Converters/GeometryEnumerableConverter.cs create mode 100644 src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs diff --git a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs index 0cd89bc..d7aba43 100644 --- a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs +++ b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs @@ -1,10 +1,10 @@ -using GeoJSON.Net.CoordinateReferenceSystem; -using GeoJSON.Net.Feature; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.CoordinateReferenceSystem; +using GeoJSON.Text.Feature; +using GeoJSON.Text.Geometry; using NUnit.Framework; +using System.Text.Json; -namespace GeoJSON.Net.Tests.CoordinateReferenceSystem +namespace GeoJSON.Text.Tests.CoordinateReferenceSystem { [TestFixture] public class DefaultCrsTests : TestBase @@ -14,7 +14,7 @@ public void Can_Serialize_Does_Not_Output_Crs_Property() { var collection = new FeatureCollection(); - var json = JsonConvert.SerializeObject(collection); + var json = JsonSerializer.Serialize(collection); Assert.IsTrue(!json.Contains("\"crs\"")); } @@ -23,8 +23,8 @@ public void Can_Serialize_Does_Not_Output_Crs_Property() public void Can_Deserialize_When_Json_Does_Not_Contain_Crs_Property() { var json = "{\"coordinates\":[90.65464646,53.2455662,200.4567],\"type\":\"Point\"}"; - - var point = JsonConvert.DeserializeObject(json); + + var point = JsonSerializer.Deserialize(json); Assert.IsNull(point.CRS); } @@ -34,7 +34,7 @@ public void Can_Deserialize_CRS_issue_89() { var json = "{\"coordinates\": [ 90.65464646, 53.2455662, 200.4567 ], \"type\": \"Point\", \"crs\": { \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" }}}"; - var point = JsonConvert.DeserializeObject(json); + var point = JsonSerializer.Deserialize(json); Assert.IsNotNull(point.CRS); Assert.AreEqual(CRSType.Name, point.CRS.Type); @@ -47,7 +47,7 @@ public void Can_Serialize_CRS_issue_89() "{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"TEST NAME\"},\"type\":\"name\"}}"; var point = new Point(new Position(12.34, 34.56)) { CRS = new NamedCRS("TEST NAME") }; - var json = JsonConvert.SerializeObject(point); + var json = JsonSerializer.Serialize(point); Assert.IsNotNull(json); Assert.AreEqual(expected, json); @@ -60,7 +60,7 @@ public void Can_Serialize_DefaultCRS_issue_89() "{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"urn:ogc:def:crs:OGC::CRS84\"},\"type\":\"name\"}}"; var point = new Point(new Position(12.34, 34.56)) { CRS = new NamedCRS("urn:ogc:def:crs:OGC::CRS84") }; - var json = JsonConvert.SerializeObject(point); + var json = JsonSerializer.Serialize(point); Assert.IsNotNull(json); Assert.AreEqual(expected, json); diff --git a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs index 91d4091..d21efa8 100644 --- a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs +++ b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs @@ -1,10 +1,10 @@ using System; -using GeoJSON.Net.CoordinateReferenceSystem; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using GeoJSON.Text.CoordinateReferenceSystem; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.CoordinateReferenceSystem +namespace GeoJSON.Text.Tests.CoordinateReferenceSystem { [TestFixture] public class LinkedCRSTests : TestBase @@ -41,7 +41,7 @@ public void Has_Type_Property() public void Can_Serialize() { var collection = new Point(new Position(1, 2, 3)) { CRS = new LinkedCRS(Href) }; - var actualJson = JsonConvert.SerializeObject(collection); + var actualJson = JsonSerializer.Serialize(collection); JsonAssert.Contains("{\"properties\":{\"href\":\"http://localhost\"},\"type\":\"link\"}", actualJson); } @@ -50,7 +50,7 @@ public void Can_Serialize() public void Can_Deserialize_CRS_issue_101() { const string pointJson = "{\"type\":\"Point\",\"coordinates\":[2.0,1.0,3.0],\"crs\":{\"properties\":{\"href\":\"http://localhost\"},\"type\":\"link\"}}"; - var pointWithCRS = JsonConvert.DeserializeObject(pointJson); + var pointWithCRS = JsonSerializer.Deserialize(pointJson); var linkCRS = pointWithCRS.CRS as LinkedCRS; Assert.IsNotNull(linkCRS); @@ -73,14 +73,11 @@ public void Ctor_Throws_ArgumentNullExpection_When_Href_Uri_Is_Null() [Test] public void Ctor_Throws_ArgumentExpection_When_Href_Is_Not_Dereferencable_Uri() { -#if NETCOREAPP1_1 - System.Globalization.CultureInfo.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); -#else System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); -#endif + // Assert that a argument exception is thrown, and that it is for href. var argumentExpection = Assert.Throws(() => { var crs = new LinkedCRS("http://not-a-valid-<>-url"); }); - Assert.AreEqual($"must be a dereferenceable URI{Environment.NewLine}Parameter name: href", argumentExpection.Message); + Assert.True(argumentExpection.Message.ToLower().Contains("href")); } [Test] diff --git a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs index 88bdc2b..9844405 100644 --- a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs +++ b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/NamedCrsTests.cs @@ -1,10 +1,10 @@ using System; -using GeoJSON.Net.CoordinateReferenceSystem; -using GeoJSON.Net.Feature; -using Newtonsoft.Json; +using System.Text.Json; +using GeoJSON.Text.CoordinateReferenceSystem; +using GeoJSON.Text.Feature; using NUnit.Framework; -namespace GeoJSON.Net.Tests.CoordinateReferenceSystem +namespace GeoJSON.Text.Tests.CoordinateReferenceSystem { [TestFixture] public class NamedCRSTests : TestBase @@ -32,7 +32,7 @@ public void Has_Name_Property_With_Name() public void Can_Serialize() { var collection = new FeatureCollection() { CRS = new NamedCRS("EPSG:31370") }; - var actualJson = JsonConvert.SerializeObject(collection); + var actualJson = JsonSerializer.Serialize(collection); JsonAssert.Contains("{\"properties\":{\"name\":\"EPSG:31370\"},\"type\":\"name\"}", actualJson); } diff --git a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs index e644807..6d8cea4 100644 --- a/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs +++ b/src/GeoJSON.Text.Tests/CoordinateReferenceSystem/UnspecifiedCRSTests.cs @@ -1,9 +1,9 @@ -using GeoJSON.Net.CoordinateReferenceSystem; -using GeoJSON.Net.Feature; -using Newtonsoft.Json; +using GeoJSON.Text.CoordinateReferenceSystem; +using GeoJSON.Text.Feature; using NUnit.Framework; +using System.Text.Json; -namespace GeoJSON.Net.Tests.CoordinateReferenceSystem +namespace GeoJSON.Text.Tests.CoordinateReferenceSystem { [TestFixture] public class UnspecifiedCRSTests : TestBase @@ -21,7 +21,7 @@ public void Can_Serialize_To_Null() { var collection = new FeatureCollection { CRS = new UnspecifiedCRS() }; var expectedJson = "{\"type\":\"FeatureCollection\",\"crs\":null,\"features\":[] }"; - var actualJson = JsonConvert.SerializeObject(collection); + var actualJson = JsonSerializer.Serialize(collection); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -30,7 +30,7 @@ public void Can_Serialize_To_Null() public void Can_Deserialize_From_Null() { var json = "{\"type\":\"FeatureCollection\",\"crs\":null,\"features\":[] }"; - var featureCollection = JsonConvert.DeserializeObject(json); + var featureCollection = JsonSerializer.Deserialize(json); Assert.IsInstanceOf(featureCollection.CRS); } diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs b/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs index 8ddb9fc..3c6d6cf 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs +++ b/src/GeoJSON.Text.Tests/Feature/FeatureCollectionTests.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using GeoJSON.Net.Feature; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using GeoJSON.Text.Feature; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { [TestFixture] public class FeatureCollectionTests : TestBase @@ -25,7 +25,7 @@ public void Can_Deserialize() { string json = GetExpectedJson(); - var featureCollection = JsonConvert.DeserializeObject(json); + var featureCollection = JsonSerializer.Deserialize(json); Assert.IsNotNull(featureCollection.Features); Assert.AreEqual(featureCollection.Features.Count, 3); @@ -52,17 +52,17 @@ public void FeatureCollectionSerialization() { "test2", 2 } }; - var feature = new Net.Feature.Feature(geom, props); + var feature = new Text.Feature.Feature(geom, props); model.Features.Add(feature); } - var actualJson = JsonConvert.SerializeObject(model); + var actualJson = JsonSerializer.Serialize(model); Assert.IsNotNull(actualJson); Assert.IsFalse(string.IsNullOrEmpty(actualJson)); } - + [Test] public void FeatureCollection_Equals_GetHashCode_Contract() { @@ -76,12 +76,12 @@ public void FeatureCollection_Equals_GetHashCode_Contract() public void Serialized_And_Deserialized_FeatureCollection_Equals_And_Share_HashCode() { var leftFc = GetFeatureCollection(); - var leftJson = JsonConvert.SerializeObject(leftFc); - var left = JsonConvert.DeserializeObject(leftJson); + var leftJson = JsonSerializer.Serialize(leftFc); + var left = JsonSerializer.Deserialize(leftJson); var rightFc = GetFeatureCollection(); - var rightJson = JsonConvert.SerializeObject(rightFc); - var right = JsonConvert.DeserializeObject(rightJson); + var rightJson = JsonSerializer.Serialize(rightFc); + var right = JsonSerializer.Deserialize(rightJson); Assert_Are_Equal(left, right); } @@ -108,7 +108,7 @@ public void FeatureCollection_Test_IndexOf() var props = FeatureTests.GetPropertiesInRandomOrder(); - var feature = new Net.Feature.Feature(geom, props, id); + var feature = new Text.Feature.Feature(geom, props, id); model.Features.Add(feature); } @@ -124,7 +124,7 @@ public void FeatureCollection_Test_IndexOf() Assert.AreEqual(expectedId, actualId); Assert.AreEqual(expectedIndex, actualIndex); - Assert.Inconclusive("not supported. the Feature.Id is optional. " + + Assert.Inconclusive("not supported. the Feature.Id is optional. " + " create a new class that inherits from" + " Feature and then override Equals and GetHashCode"); @@ -146,7 +146,7 @@ private FeatureCollection GetFeatureCollection() var props = FeatureTests.GetPropertiesInRandomOrder(); - var feature = new Net.Feature.Feature(geom, props); + var feature = new Text.Feature.Feature(geom, props); model.Features.Add(feature); } return model; diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureTests.cs b/src/GeoJSON.Text.Tests/Feature/FeatureTests.cs index 07259f9..47d4df9 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureTests.cs +++ b/src/GeoJSON.Text.Tests/Feature/FeatureTests.cs @@ -1,11 +1,11 @@ -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.Geometry; using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { [TestFixture] public class FeatureTests : TestBase @@ -15,14 +15,14 @@ public void Can_Deserialize_Point_Feature() { var json = GetExpectedJson(); - var feature = JsonConvert.DeserializeObject(json); + var feature = JsonSerializer.Deserialize(json); Assert.IsNotNull(feature); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Any()); Assert.IsTrue(feature.Properties.ContainsKey("name")); - Assert.AreEqual(feature.Properties["name"], "Dinagat Islands"); + Assert.AreEqual(feature.Properties["name"].ToString(), "Dinagat Islands"); Assert.AreEqual("test-id", feature.Id); @@ -52,8 +52,7 @@ public void Can_Serialize_LineString_Feature() var geometry = new LineString(coordinates[0]); - - var actualJson = JsonConvert.SerializeObject(new Net.Feature.Feature(geometry)); + var actualJson = JsonSerializer.Serialize(new Text.Feature.Feature(geometry)); Console.WriteLine(actualJson); @@ -85,7 +84,7 @@ public void Can_Serialize_MultiLineString_Feature() var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(new Net.Feature.Feature(geometry)); + var actualJson = JsonSerializer.Serialize(new Text.Feature.Feature(geometry)); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -96,7 +95,7 @@ public void Can_Serialize_Point_Feature() var geometry = new Point(new Position(1, 2)); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(new Net.Feature.Feature(geometry)); + var actualJson = JsonSerializer.Serialize(new Text.Feature.Feature(geometry)); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -114,10 +113,10 @@ public void Can_Serialize_Polygon_Feature() var polygon = new Polygon(new List { new LineString(coordinates) }); var properties = new Dictionary { { "Name", "Foo" } }; - var feature = new Net.Feature.Feature(polygon, properties); + var feature = new Text.Feature.Feature(polygon, properties); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(feature); + var actualJson = JsonSerializer.Serialize(feature); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -159,10 +158,10 @@ public void Can_Serialize_MultiPolygon_Feature() }) }); - var feature = new Net.Feature.Feature(multiPolygon); + var feature = new Text.Feature.Feature(multiPolygon); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(feature); + var actualJson = JsonSerializer.Serialize(feature); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -180,10 +179,10 @@ public void Can_Serialize_Dictionary_Subclass() StringProperty = "Hello, GeoJSON !" }; - Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); + Text.Feature.Feature feature = new Text.Feature.Feature(new Point(new Position(10, 10)), properties); var expectedJson = this.GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(feature); + var actualJson = JsonSerializer.Serialize(feature); Assert.False(string.IsNullOrEmpty(expectedJson)); JsonAssert.AreEqual(expectedJson, actualJson); @@ -202,7 +201,7 @@ public void Ctor_Can_Add_Properties_Using_Object() StringProperty = "Hello, GeoJSON !" }; - Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); + Text.Feature.Feature feature = new Text.Feature.Feature(new Point(new Position(10, 10)), properties); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Count > 1); @@ -224,7 +223,7 @@ public void Ctor_Can_Add_Properties_Using_Object_Inheriting_Dictionary() StringProperty = "Hello, GeoJSON !" }; - Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); + Text.Feature.Feature feature = new Text.Feature.Feature(new Point(new Position(10, 10)), properties); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Count > 1); @@ -237,7 +236,7 @@ public void Ctor_Can_Add_Properties_Using_Object_Inheriting_Dictionary() [Test] public void Ctor_Creates_Properties_Collection_When_Passed_Null_Proper_Object() { - Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), (object)null); + Text.Feature.Feature feature = new Text.Feature.Feature(new Point(new Position(10, 10)), (object)null); Assert.IsNotNull(feature.Properties); CollectionAssert.IsEmpty(feature.Properties); @@ -258,7 +257,7 @@ public void Feature_Equals_GetHashCode_Contract_Properties_Of_Objects() DoubleProperty = 1.2345d }; - var left = new Net.Feature.Feature(new Point(new Position(10, 10)), leftProp); + var left = new Text.Feature.Feature(new Point(new Position(10, 10)), leftProp); var rightProp = new TestFeatureProperty { @@ -270,7 +269,7 @@ public void Feature_Equals_GetHashCode_Contract_Properties_Of_Objects() StringProperty = "Hello, GeoJSON !" }; - var right = new Net.Feature.Feature(new Point(new Position(10, 10)), rightProp); + var right = new Text.Feature.Feature(new Point(new Position(10, 10)), rightProp); Assert_Are_Equal(left, right); } @@ -284,11 +283,11 @@ public void Feature_Equals_GetHashCode_Contract_Dictionary() var geometry10 = new Position(10, 10); var geometry20 = new Position(20, 20); - var left = new Net.Feature.Feature(new Point( + var left = new Text.Feature.Feature(new Point( geometry10), leftDictionary, "abc"); - var right = new Net.Feature.Feature(new Point( + var right = new Text.Feature.Feature(new Point( geometry20), rightDictionary, "abc"); @@ -296,11 +295,11 @@ public void Feature_Equals_GetHashCode_Contract_Dictionary() Assert_Are_Not_Equal(left, right); // different geometries - left = new Net.Feature.Feature(new Point( + left = new Text.Feature.Feature(new Point( geometry10), leftDictionary, "abc"); - right = new Net.Feature.Feature(new Point( + right = new Text.Feature.Feature(new Point( geometry10), rightDictionary, "abc"); // identical geometries, different ids and or properties or not compared @@ -314,43 +313,43 @@ public void Serialized_And_Deserialized_Feature_Equals_And_Share_HashCode() { var geometry = GetGeometry(); - var leftFeature = new Net.Feature.Feature(geometry); - var leftJson = JsonConvert.SerializeObject(leftFeature); - var left = JsonConvert.DeserializeObject(leftJson); + var leftFeature = new Text.Feature.Feature(geometry); + var leftJson = JsonSerializer.Serialize(leftFeature); + var left = JsonSerializer.Deserialize(leftJson); - var rightFeature = new Net.Feature.Feature(geometry); - var rightJson = JsonConvert.SerializeObject(rightFeature); - var right = JsonConvert.DeserializeObject(rightJson); + var rightFeature = new Text.Feature.Feature(geometry); + var rightJson = JsonSerializer.Serialize(rightFeature); + var right = JsonSerializer.Deserialize(rightJson); Assert_Are_Equal(left, right); - leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder()); - leftJson = JsonConvert.SerializeObject(leftFeature); - left = JsonConvert.DeserializeObject(leftJson); + leftFeature = new Text.Feature.Feature(geometry, GetPropertiesInRandomOrder()); + leftJson = JsonSerializer.Serialize(leftFeature); + left = JsonSerializer.Deserialize(leftJson); - rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder()); - rightJson = JsonConvert.SerializeObject(rightFeature); - right = JsonConvert.DeserializeObject(rightJson); + rightFeature = new Text.Feature.Feature(geometry, GetPropertiesInRandomOrder()); + rightJson = JsonSerializer.Serialize(rightFeature); + right = JsonSerializer.Deserialize(rightJson); Assert_Are_Equal(left, right); // assert properties doesn't influence comparison and hashcode - leftFeature = new Net.Feature.Feature(geometry, null, "abc_abc"); - leftJson = JsonConvert.SerializeObject(leftFeature); - left = JsonConvert.DeserializeObject(leftJson); + leftFeature = new Text.Feature.Feature(geometry, null, "abc_abc"); + leftJson = JsonSerializer.Serialize(leftFeature); + left = JsonSerializer.Deserialize(leftJson); - rightFeature = new Net.Feature.Feature(geometry, null, "xyz_XYZ"); - rightJson = JsonConvert.SerializeObject(rightFeature); - right = JsonConvert.DeserializeObject(rightJson); + rightFeature = new Text.Feature.Feature(geometry, null, "xyz_XYZ"); + rightJson = JsonSerializer.Serialize(rightFeature); + right = JsonSerializer.Deserialize(rightJson); Assert_Are_Equal(left, right); // assert id's doesn't influence comparison and hashcode - leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); - leftJson = JsonConvert.SerializeObject(leftFeature); - left = JsonConvert.DeserializeObject(leftJson); + leftFeature = new Text.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); + leftJson = JsonSerializer.Serialize(leftFeature); + left = JsonSerializer.Deserialize(leftJson); - rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); - rightJson = JsonConvert.SerializeObject(rightFeature); - right = JsonConvert.DeserializeObject(rightJson); + rightFeature = new Text.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); + rightJson = JsonSerializer.Serialize(rightFeature); + right = JsonSerializer.Deserialize(rightJson); Assert_Are_Equal(left, right); // assert id's + properties doesn't influence comparison and hashcode } @@ -361,7 +360,7 @@ public void Feature_Equals_Null_Issue94() bool equal1 = true; bool equal2 = true; - var feature = new Net.Feature.Feature(new Point(new Position(12, 123))); + var feature = new Text.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { equal1 = feature.Equals(null); @@ -377,7 +376,7 @@ public void Feature_Null_Instance_Equals_Null_Issue94() { var equal1 = true; - Net.Feature.Feature feature = null; + Text.Feature.Feature feature = null; Assert.DoesNotThrow(() => { equal1 = feature != null; @@ -392,10 +391,12 @@ public void Feature_Equals_Itself_Issue94() bool equal1 = false; bool equal2 = false; - var feature = new Net.Feature.Feature(new Point(new Position(12, 123))); + var feature = new Text.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { +#pragma warning disable CS1718 // Comparison made to same variable equal1 = feature == feature; +#pragma warning restore CS1718 // Comparison made to same variable equal2 = feature.Equals(feature); }); @@ -409,8 +410,8 @@ public void Feature_Equals_Geometry_Null_Issue115() bool equal1 = false; bool equal2 = false; - var feature1 = new Net.Feature.Feature(null); - var feature2 = new Net.Feature.Feature(new Point(new Position(12, 123))); + var feature1 = new Text.Feature.Feature(null); + var feature2 = new Text.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { @@ -428,8 +429,8 @@ public void Feature_Equals_Other_Geometry_Null_Issue115() bool equal1 = false; bool equal2 = false; - var feature1 = new Net.Feature.Feature(new Point(new Position(12, 123))); - var feature2 = new Net.Feature.Feature(null); + var feature1 = new Text.Feature.Feature(new Point(new Position(12, 123))); + var feature2 = new Text.Feature.Feature(null); Assert.DoesNotThrow(() => { @@ -447,8 +448,8 @@ public void Feature_Equals_All_Geometry_Null_Issue115() bool equal1 = false; bool equal2 = false; - var feature1 = new Net.Feature.Feature(null); - var feature2 = new Net.Feature.Feature(null); + var feature1 = new Text.Feature.Feature(null); + var feature2 = new Text.Feature.Feature(null); Assert.DoesNotThrow(() => { @@ -505,7 +506,7 @@ public static IDictionary GetPropertiesInRandomOrder() return randomlyOrdered; } - private void Assert_Are_Equal(Net.Feature.Feature left, Net.Feature.Feature right) + private void Assert_Are_Equal(Text.Feature.Feature left, Text.Feature.Feature right) { Assert.AreEqual(left, right); @@ -524,7 +525,7 @@ private void Assert_Are_Equal(Net.Feature.Feature left, Net.Feature.Feature righ Assert.AreEqual(left.GetHashCode(), right.GetHashCode()); } - private void Assert_Are_Not_Equal(Net.Feature.Feature left, Net.Feature.Feature right) + private void Assert_Are_Not_Equal(Text.Feature.Feature left, Text.Feature.Feature right) { Assert.AreNotEqual(left, right); diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json index 7d9ccc5..384bd4b 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json +++ b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Dictionary_Subclass.json @@ -3,8 +3,8 @@ "geometry":{ "type":"Point", "coordinates":[ - 10.0, - 10.0 + 10, + 10 ] }, "properties":{ diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json index f84cdc9..777ae16 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json +++ b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_LineString_Feature.json @@ -1,13 +1,25 @@ { - "geometry": { - "coordinates": [ - [4.8892593383789062, 52.370725881211314], - [4.8952674865722656, 52.3711451105601], - [4.8920917510986328, 52.369310952782627], - [4.8892593383789062, 52.370725881211314] - ], - "type": "LineString" - }, - "properties": {}, - "type": "Feature" + "type": "Feature", + "geometry": { + "coordinates": [ + [ + 4.8892593383789062, + 52.370725881211314 + ], + [ + 4.8952674865722656, + 52.3711451105601 + ], + [ + 4.8920917510986328, + 52.369310952782627 + ], + [ + 4.8892593383789062, + 52.370725881211314 + ] + ], + "type": "LineString" + }, + "properties": {} } \ No newline at end of file diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json index a674064..20880e6 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json +++ b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_MultiPolygon_Feature.json @@ -3,27 +3,27 @@ "coordinates": [ [ [ - [0.0, 0.0], - [1.0, 0.0], - [1.0, 1.0], - [0.0, 1.0], - [0.0, 0.0] + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0] ] ], [ [ - [70.0, 70.0], - [71.0, 70.0], - [71.0, 71.0], - [70.0, 71.0], - [70.0, 70.0] + [70, 70], + [71, 70], + [71, 71], + [70, 71], + [70, 70] ], [ - [80.0, 80.0], - [81.0, 80.0], - [81.0, 81.0], - [80.0, 81.0], - [80.0, 80.0] + [80, 80], + [81, 80], + [81, 81], + [80, 81], + [80, 80] ] ] ], diff --git a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json index dab8655..3e8c53f 100644 --- a/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json +++ b/src/GeoJSON.Text.Tests/Feature/FeatureTests_Can_Serialize_Point_Feature.json @@ -1,6 +1,6 @@ { "geometry": { - "coordinates": [2.0, 1.0], + "coordinates": [2, 1], "type": "Point" }, "properties": {}, diff --git a/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs index 39ee3ac..d19d051 100644 --- a/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs +++ b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; using System.Linq; -using GeoJSON.Net.Feature; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Feature; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { [TestFixture] internal class GenericFeatureTests : TestBase @@ -15,14 +16,15 @@ public void Can_Deserialize_Point_Feature() { var json = GetExpectedJson(); - var feature = JsonConvert.DeserializeObject>(json); + var feature = JsonSerializer.Deserialize>(json); Assert.IsNotNull(feature); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Any()); Assert.IsTrue(feature.Properties.ContainsKey("name")); - Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); + string name = feature.Properties["name"].ToString(); + Assert.AreEqual("Dinagat Islands", name); Assert.AreEqual("test-id", feature.Id); @@ -31,20 +33,19 @@ public void Can_Deserialize_Point_Feature() Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude); Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude); } - [Test] public void Can_Deserialize_LineString_Feature() { var json = GetExpectedJson(); - var feature = JsonConvert.DeserializeObject>(json); - + var feature = JsonSerializer.Deserialize>(json); + Assert.IsNotNull(feature); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Any()); Assert.IsTrue(feature.Properties.ContainsKey("name")); - Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); + Assert.AreEqual("Dinagat Islands", feature.Properties["name"].ToString()); Assert.AreEqual("test-id", feature.Id); @@ -84,9 +85,9 @@ public void Feature_Generic_Equals_Null_Issure94() private class TypedFeatureProps { - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -94,7 +95,7 @@ private class TypedFeatureProps public void Can_Deserialize_Typed_Point_Feature() { var json = GetExpectedJson(); - var feature = JsonConvert.DeserializeObject>(json); + var feature = JsonSerializer.Deserialize>(json); Assert.IsNotNull(feature); @@ -120,7 +121,7 @@ public void Can_Serialize_Typed_Point_Feature() var feature = new Feature(geometry, props, "no id there"); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(feature); + var actualJson = JsonSerializer.Serialize(feature); JsonAssert.AreEqual(expectedJson, actualJson); } diff --git a/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json index 4e68aff..328b164 100644 --- a/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json +++ b/src/GeoJSON.Text.Tests/Feature/GenericFeatureTests_Can_Serialize_Typed_Point_Feature.json @@ -1,6 +1,6 @@ { "geometry": { - "coordinates": [ 2.0, 1.0 ], + "coordinates": [ 2, 1 ], "type": "Point" }, "properties": { diff --git a/src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs b/src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs index a4ecc62..7b411e6 100644 --- a/src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs +++ b/src/GeoJSON.Text.Tests/Feature/TestFeatureEnum.cs @@ -1,4 +1,4 @@ -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { internal enum TestFeatureEnum { diff --git a/src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs b/src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs index 0b71acb..3506d76 100644 --- a/src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs +++ b/src/GeoJSON.Text.Tests/Feature/TestFeatureProperty.cs @@ -1,6 +1,6 @@ using System; -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { internal class TestFeatureProperty { diff --git a/src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs b/src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs index 64512f6..c503fab 100644 --- a/src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs +++ b/src/GeoJSON.Text.Tests/Feature/TestFeaturePropertyDictionary.cs @@ -1,4 +1,4 @@ -namespace GeoJSON.Net.Tests.Feature +namespace GeoJSON.Text.Tests.Feature { using System; using System.Collections; diff --git a/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj b/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj index 37efa30..ec8b18d 100644 --- a/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj +++ b/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj @@ -2,26 +2,68 @@ {6C93B314-9208-4684-B873-172F7EC81689} - GeoJSON.Net.Tests - GeoJSON.Net.Tests - net461;netcoreapp3.1 + GeoJSON.Text.Tests + GeoJSON.Text.Tests + netcoreapp3.1;net5;net6 false - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - Always - - - Always - - diff --git a/src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs b/src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs index 8f355b4..b06ff50 100644 --- a/src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/GeometryTests.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; -using GeoJSON.Net.Converters; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Converters; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class GeometryTests : TestBase @@ -116,9 +117,9 @@ public static IEnumerable Geometries [TestCaseSource(typeof(GeometryTests), nameof(Geometries))] public void Can_Serialize_And_Deserialize_Geometry(IGeometryObject geometry) { - var json = JsonConvert.SerializeObject(geometry); + var json = JsonSerializer.Serialize(geometry); - var deserializedGeometry = JsonConvert.DeserializeObject(json, new GeometryConverter()); + var deserializedGeometry = JsonSerializer.Deserialize(json); Assert.AreEqual(geometry, deserializedGeometry); } @@ -127,7 +128,8 @@ public void Can_Serialize_And_Deserialize_Geometry(IGeometryObject geometry) [TestCaseSource(typeof(GeometryTests), nameof(Geometries))] public void Serialization_Observes_Indenting_Setting_Of_Serializer(IGeometryObject geometry) { - var json = JsonConvert.SerializeObject(geometry, Formatting.Indented); + var options = new JsonSerializerOptions { WriteIndented = true }; + var json = JsonSerializer.Serialize(geometry, options); Assert.IsTrue(json.Contains(Environment.NewLine)); } @@ -135,7 +137,7 @@ public void Serialization_Observes_Indenting_Setting_Of_Serializer(IGeometryObje [TestCaseSource(typeof(GeometryTests), nameof(Geometries))] public void Serialization_Observes_No_Indenting_Setting_Of_Serializer(IGeometryObject geometry) { - var json = JsonConvert.SerializeObject(geometry, Formatting.None); + var json = JsonSerializer.Serialize(geometry); Assert.IsFalse(json.Contains(Environment.NewLine)); Assert.IsFalse(json.Contains(" ")); } @@ -146,9 +148,9 @@ public void Can_Serialize_And_Deserialize_Geometry_As_Object_Property(IGeometryO { var classWithGeometry = new ClassWithGeometryProperty(geometry); - var json = JsonConvert.SerializeObject(classWithGeometry); + var json = JsonSerializer.Serialize(classWithGeometry); - var deserializedClassWithGeometry = JsonConvert.DeserializeObject(json); + var deserializedClassWithGeometry = JsonSerializer.Deserialize(json); Assert.AreEqual(classWithGeometry, deserializedClassWithGeometry); } @@ -159,13 +161,13 @@ public void Serialized_And_Deserialized_Equals_And_Share_HashCode(IGeometryObjec { var classWithGeometry = new ClassWithGeometryProperty(geometry); - var json = JsonConvert.SerializeObject(classWithGeometry); + var json = JsonSerializer.Serialize(classWithGeometry); - var deserializedClassWithGeometry = JsonConvert.DeserializeObject(json); + var deserializedClassWithGeometry = JsonSerializer.Deserialize(json); var actual = classWithGeometry; var expected = deserializedClassWithGeometry; - + Assert.IsTrue(actual.Equals(expected)); Assert.IsTrue(actual.Equals(actual)); diff --git a/src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs b/src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs index d203b87..0f77d8a 100644 --- a/src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/LineStringTests.cs @@ -1,10 +1,10 @@ +using GeoJSON.Text.Geometry; +using NUnit.Framework; using System; using System.Collections.Generic; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using NUnit.Framework; +using System.Text.Json; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class LineStringTests : TestBase @@ -40,7 +40,7 @@ public void Is_Not_Closed() Assert.IsFalse(lineString.IsClosed()); } - + [Test] public void Can_Serialize() @@ -55,7 +55,7 @@ public void Can_Serialize() var lineString = new LineString(coordinates); - var actualJson = JsonConvert.SerializeObject(lineString); + var actualJson = JsonSerializer.Serialize(lineString); JsonAssert.AreEqual(GetExpectedJson(), actualJson); } @@ -74,7 +74,7 @@ public void Can_Deserialize() var expectedLineString = new LineString(coordinates); var json = GetExpectedJson(); - var actualLineString = JsonConvert.DeserializeObject(json); + var actualLineString = JsonSerializer.Deserialize(json); Assert.AreEqual(expectedLineString, actualLineString); diff --git a/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs index ac2b643..73bbb79 100644 --- a/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/MultiLineStringTests.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.Geometry; using NUnit.Framework; +using System.Collections.Generic; +using System.Text.Json; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class MultiLineStringTests : TestBase @@ -29,7 +29,7 @@ public void Can_Deserialize() }) }); - var multiLineString = JsonConvert.DeserializeObject(json); + var multiLineString = JsonSerializer.Deserialize(json); Assert.IsNotNull(multiLineString); Assert.AreEqual(expectedMultiLineString, multiLineString); @@ -55,7 +55,7 @@ public void Can_Serialize() }); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(expectedMultiLineString); + var actualJson = JsonSerializer.Serialize(expectedMultiLineString); JsonAssert.AreEqual(expectedJson, actualJson); } diff --git a/src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs index 741f068..00f2c2f 100644 --- a/src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/MultiPointTests.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.Geometry; using NUnit.Framework; +using System.Collections.Generic; +using System.Text.Json; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class MultiPointTests : TestBase @@ -21,7 +21,7 @@ public void Can_Serialize() var multiPoint = new MultiPoint(points); - var actualJson = JsonConvert.SerializeObject(multiPoint); + var actualJson = JsonSerializer.Serialize(multiPoint); JsonAssert.AreEqual(GetExpectedJson(), actualJson); } @@ -38,7 +38,7 @@ public void Can_Deserialize() var expectedMultiPoint = new MultiPoint(points); var json = GetExpectedJson(); - var actualMultiPoint = JsonConvert.DeserializeObject(json); + var actualMultiPoint = JsonSerializer.Deserialize(json); Assert.AreEqual(expectedMultiPoint, actualMultiPoint); } diff --git a/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs index d9c3aa7..38b8fdd 100644 --- a/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class MultiPolygonTests : TestBase @@ -15,7 +15,7 @@ public void Can_Deserialize() var expectMultiPolygon = GetMultiPolygon(); - var actualMultiPolygon = JsonConvert.DeserializeObject(json); + var actualMultiPolygon = JsonSerializer.Deserialize(json); Assert.AreEqual(expectMultiPolygon, actualMultiPolygon); } @@ -101,7 +101,7 @@ public void Can_Serialize() var expectedJson = GetExpectedJson(); // Act - var actualJson = JsonConvert.SerializeObject(multiPolygon); + var actualJson = JsonSerializer.Serialize(multiPolygon); // Assert JsonAssert.AreEqual(expectedJson, actualJson); diff --git a/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json index 3b9d4a6..148f972 100644 --- a/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json +++ b/src/GeoJSON.Text.Tests/Geometry/MultiPolygonTests_Can_Serialize.json @@ -2,27 +2,27 @@ "coordinates": [ [ [ - [0.0, 0.0], - [1.0, 0.0], - [1.0, 1.0], - [0.0, 1.0], - [0.0, 0.0] + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0] ] ], [ [ - [60.0, 60.0], - [61.0, 60.0], - [61.0, 61.0], - [60.0, 61.0], - [60.0, 60.0] + [60, 60], + [61, 60], + [61, 61], + [60, 61], + [60, 60] ], [ - [70.0, 70.0], - [70.0, 71.0], - [71.0, 71.0], - [71.0, 70.0], - [70.0, 70.0] + [70, 70], + [70, 71], + [71, 71], + [71, 70], + [70, 70] ] ] ], diff --git a/src/GeoJSON.Text.Tests/Geometry/PointTests.cs b/src/GeoJSON.Text.Tests/Geometry/PointTests.cs index 391f50a..e203f82 100644 --- a/src/GeoJSON.Text.Tests/Geometry/PointTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/PointTests.cs @@ -1,8 +1,9 @@ -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.Geometry; using NUnit.Framework; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class PointTests : TestBase @@ -14,7 +15,7 @@ public void Can_Serialize_With_Lat_Lon() var expectedJson = "{\"coordinates\":[90.65464646,53.2455662],\"type\":\"Point\"}"; - var actualJson = JsonConvert.SerializeObject(point); + var actualJson = JsonSerializer.Serialize(point); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -26,7 +27,7 @@ public void Can_Serialize_With_Lat_Lon_Alt() var expectedJson = "{\"coordinates\":[90.65464646,53.2455662,200.4567],\"type\":\"Point\"}"; - var actualJson = JsonConvert.SerializeObject(point); + var actualJson = JsonSerializer.Serialize(point); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -38,7 +39,7 @@ public void Can_Deserialize_With_Lat_Lon_Alt() var expectedPoint = new Point(new Position(53.2455662, 90.65464646, 200.4567)); - var actualPoint = JsonConvert.DeserializeObject(json); + var actualPoint = JsonSerializer.Deserialize(json); Assert.IsNotNull(actualPoint); Assert.IsNotNull(actualPoint.Coordinates); @@ -55,7 +56,7 @@ public void Can_Deserialize_With_Lat_Lon() var expectedPoint = new Point(new Position(53.2455662, 90.65464646)); - var actualPoint = JsonConvert.DeserializeObject(json); + var actualPoint = JsonSerializer.Deserialize(json); Assert.IsNotNull(actualPoint); Assert.IsNotNull(actualPoint.Coordinates); @@ -73,7 +74,7 @@ public void Equals_GetHashCode_Contract() var expectedPoint = new Point(new Position(53.2455662, 90.65464646)); - var actualPoint = JsonConvert.DeserializeObject(json); + var actualPoint = JsonSerializer.Deserialize(json); Assert.AreEqual(expectedPoint, actualPoint); Assert.IsTrue(expectedPoint.Equals(actualPoint)); @@ -89,7 +90,8 @@ public void Can_Serialize_With_Lat_Lon_Alt_DefaultValueHandling_Ignore() var expectedJson = "{\"coordinates\":[90.65464646,53.2455662,200.4567],\"type\":\"Point\"}"; - var actualJson = JsonConvert.SerializeObject(point, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); + var options = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault }; + var actualJson = JsonSerializer.Serialize(point, options ); JsonAssert.AreEqual(expectedJson, actualJson); } diff --git a/src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs b/src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs index b55f535..528ebdb 100644 --- a/src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs +++ b/src/GeoJSON.Text.Tests/Geometry/PolygonTests.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; -using GeoJSON.Net.Converters; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using GeoJSON.Text.Converters; +using GeoJSON.Text.Geometry; using NUnit.Framework; -namespace GeoJSON.Net.Tests.Geometry +namespace GeoJSON.Text.Tests.Geometry { [TestFixture] public class PolygonTests : TestBase @@ -24,7 +24,7 @@ public void Can_Serialize() }); var expectedJson = GetExpectedJson(); - var actualJson = JsonConvert.SerializeObject(polygon); + var actualJson = JsonSerializer.Serialize(polygon); JsonAssert.AreEqual(expectedJson, actualJson); } @@ -43,13 +43,8 @@ public void Can_RoundTrip_IGeometryObject() }) }); - var serializerSettings = new JsonSerializerSettings() - { - Converters = new List() { new GeometryConverter() } - }; - - var json = JsonConvert.SerializeObject(polygon, serializerSettings); - var result = JsonConvert.DeserializeObject(json, serializerSettings); + var json = JsonSerializer.Serialize(polygon); + var result = JsonSerializer.Deserialize(json); Assert.AreEqual(result, polygon); } @@ -264,7 +259,7 @@ public void Can_Deserialize_With_Exterior_And_Inner_Rings() }) }); - var actualPolygon = JsonConvert.DeserializeObject(json); + var actualPolygon = JsonSerializer.Deserialize(json); Assert.AreEqual(expectedPolygon, actualPolygon); } @@ -284,7 +279,7 @@ public void Can_Deserialize() }) }); - var actualPolygon = JsonConvert.DeserializeObject(json); + var actualPolygon = JsonSerializer.Deserialize(json); Assert.AreEqual(expectedPolygon, actualPolygon); } diff --git a/src/GeoJSON.Text.Tests/JsonAssert.cs b/src/GeoJSON.Text.Tests/JsonAssert.cs index fa8213c..5b8e4be 100644 --- a/src/GeoJSON.Text.Tests/JsonAssert.cs +++ b/src/GeoJSON.Text.Tests/JsonAssert.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json.Linq; using NUnit.Framework; -namespace GeoJSON.Net.Tests +namespace GeoJSON.Text.Tests { /// /// Assertions for json strings diff --git a/src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs b/src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 7e9cb7a..0000000 --- a/src/GeoJSON.Text.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © Joerg Battermann 2014 -// -// -// AssemblyInfo.cs -// -// -------------------------------------------------------------------------------------------------------------------- - -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("GeoJSON.Net.Tests")] -[assembly: AssemblyDescription("Unit tests for the GeoJSON.Net library")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Joerg Battermann")] -[assembly: AssemblyProduct("GeoJSON.Net.Tests")] -[assembly: AssemblyCopyright("Copyright © Joerg Battermann 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: AssemblyVersion("0.0.0.6")] - -[assembly: Guid("94688f28-e983-417d-8e6e-96d4c687e085")] \ No newline at end of file diff --git a/src/GeoJSON.Text.Tests/Settings.StyleCop b/src/GeoJSON.Text.Tests/Settings.StyleCop deleted file mode 100644 index 33b5d2e..0000000 --- a/src/GeoJSON.Text.Tests/Settings.StyleCop +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Jörg Battermann - Copyright © Jörg Battermann 2011 - - - - \ No newline at end of file diff --git a/src/GeoJSON.Text.Tests/TestBase.cs b/src/GeoJSON.Text.Tests/TestBase.cs index df625a4..e4fcd14 100644 --- a/src/GeoJSON.Text.Tests/TestBase.cs +++ b/src/GeoJSON.Text.Tests/TestBase.cs @@ -1,16 +1,14 @@ using System; using System.IO; +using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -namespace GeoJSON.Net.Tests +namespace GeoJSON.Text.Tests { public abstract class TestBase { private static readonly Assembly ThisAssembly = typeof(TestBase) -#if NETCOREAPP1_1 - .GetTypeInfo() -#endif .Assembly; private static readonly string AssemblyName = ThisAssembly.GetName().Name; @@ -18,7 +16,7 @@ public static string AssemblyDirectory { get { - string codeBase = ThisAssembly.CodeBase; + string codeBase = ThisAssembly.Location; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path); @@ -27,16 +25,16 @@ public static string AssemblyDirectory protected string GetExpectedJson([CallerMemberName] string name = null) { - var type = GetType().Name; - var projectFolder = GetType().Namespace.Substring(AssemblyName.Length + 1); - var path = Path.Combine(AssemblyDirectory, @"./", projectFolder, type + "_" + name + ".json"); - - if (!File.Exists(path)) + var assembly = Assembly.GetExecutingAssembly(); + var type = GetType().FullName; + using (Stream stream = assembly.GetManifestResourceStream($"{type}_{name}.json")) + using (StreamReader reader = new StreamReader(stream)) { - throw new FileNotFoundException("file not found at " + path); + string result = reader.ReadToEnd(); + return result; } - return File.ReadAllText(path); + throw new ArgumentException("File with name could not be found"); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text.Tests/app.config b/src/GeoJSON.Text.Tests/app.config deleted file mode 100644 index 8de7ab2..0000000 --- a/src/GeoJSON.Text.Tests/app.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/GeoJSON.Text.Tests/packages.config b/src/GeoJSON.Text.Tests/packages.config deleted file mode 100644 index 3b4898b..0000000 --- a/src/GeoJSON.Text.Tests/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/BoundingBoxConverter.cs b/src/GeoJSON.Text/Converters/BoundingBoxConverter.cs new file mode 100644 index 0000000..6770a7a --- /dev/null +++ b/src/GeoJSON.Text/Converters/BoundingBoxConverter.cs @@ -0,0 +1,61 @@ +// Copyright © Joerg Battermann 2014, Matt Hunt 2017 + +using GeoJSON.Text.Geometry; +using System; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Converters +{ + /// + /// Converts types to and from JSON. + /// + public class BoundingBoxConverter : JsonConverter + { + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) + { + return typeof(double[]).IsAssignableFromType(objectType); + } + + /// + /// Reads the JSON representation of the object. + /// + /// The to read from. + /// Type of the object. + /// The existing value of object being read. + /// The calling serializer. + /// + /// The object value. + /// + public override double[] Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) + { + return JsonSerializer.Deserialize(ref reader, options); + } + + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + public override void Write( + Utf8JsonWriter writer, + double[] value, + JsonSerializerOptions options) + { + // Standard serialization + JsonSerializer.Serialize(writer, value, typeof(double[]), options); + } + } +} \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/CRSBaseRequiredPropertyConverter.cs b/src/GeoJSON.Text/Converters/CRSBaseRequiredPropertyConverter.cs new file mode 100644 index 0000000..4af9171 --- /dev/null +++ b/src/GeoJSON.Text/Converters/CRSBaseRequiredPropertyConverter.cs @@ -0,0 +1,37 @@ +using GeoJSON.Text.CoordinateReferenceSystem; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Converters +{ + public class CRSBaseRequiredPropertyConverter : JsonConverter + { + public override CRSBase Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) + { + // Don't pass in options when recursively calling Deserialize. + var crsBaseClass = JsonSerializer.Deserialize(ref reader); + + if (crsBaseClass.Type == default) + throw new JsonException("Required property Type not set in the JSON"); + + if (crsBaseClass.Properties == default) + throw new JsonException("Required property Properties not set in the JSON"); + + // Check for required fields set by values in JSON + return crsBaseClass; + } + + public override void Write( + Utf8JsonWriter writer, + CRSBase crsBaseClass, + JsonSerializerOptions options) + { + // Don't pass in options when recursively calling Serialize. + JsonSerializer.Serialize(writer, crsBaseClass); + } + } +} \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/CrsConverter.cs b/src/GeoJSON.Text/Converters/CrsConverter.cs index d8fc153..5fadd87 100644 --- a/src/GeoJSON.Text/Converters/CrsConverter.cs +++ b/src/GeoJSON.Text/Converters/CrsConverter.cs @@ -1,146 +1,150 @@ -// Copyright © Matt Hunt 2021 +// Copyright © Joerg Battermann 2014, Matt Hunt 2017 using System; using System.Text.Json; using System.Text.Json.Serialization; -using GeoJSON.Net.CoordinateReferenceSystem; +using GeoJSON.Text.CoordinateReferenceSystem; -namespace GeoJSON.Net.Converters; - -/// -/// Converts types to and from JSON. -/// -/// -/// Converts types to and from JSON. -/// -public class CrsConverter : JsonConverter +namespace GeoJSON.Text.Converters { - public override bool HandleNull => true; - - /// - /// Determines whether this instance can convert the specified object type. - /// - /// Type of the object. - /// - /// true if this instance can convert the specified object type; otherwise, false. - /// - public override bool CanConvert(Type objectType) - { - return typeof(ICRSObject).IsAssignableFromType(objectType); - } - /// - /// Reads the JSON representation of the object. + /// Converts types to and from JSON. /// - /// The to read from. - /// Type of the object. - /// The existing value of object being read. - /// The calling serializer. - /// - /// The object value. - /// - /// - /// CRS must be null or a json object - /// or - /// CRS must have a "type" property - /// - public override object Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) + public class CrsConverter : JsonConverter { - if (reader.TokenType == JsonTokenType.Null) + public override bool HandleNull => true; + + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) { - return new UnspecifiedCRS(); - } - if (reader.TokenType != JsonTokenType.StartObject) - { - throw new JsonException("CRS must be null or a json object"); + return typeof(ICRSObject).IsAssignableFromType(objectType); } - var jObject = JsonDocument.ParseValue(ref reader).RootElement; - JsonElement token; - if (!jObject.TryGetProperty("type", out token)) + /// + /// Reads the JSON representation of the object. + /// + /// The to read from. + /// Type of the object. + /// The existing value of object being read. + /// The calling serializer. + /// + /// The object value. + /// + /// + /// CRS must be null or a json object + /// or + /// CRS must have a "type" property + /// + public override object Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { - throw new JsonException("CRS must have a \"type\" property"); - } - - var crsType = token.GetString(); + if (reader.TokenType == JsonTokenType.Null) + { + return new UnspecifiedCRS(); + } + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("CRS must be null or a json object"); + } - if (string.Equals("name", crsType, StringComparison.OrdinalIgnoreCase)) - { - if (jObject.TryGetProperty("properties", out var properties)) + var jObject = JsonDocument.ParseValue(ref reader).RootElement; + JsonElement token; + if (!jObject.TryGetProperty("type", out token)) { - var name = properties.GetProperty("name").GetString(); + throw new JsonException("CRS must have a \"type\" property"); + } - var target = new NamedCRS(name); - var converted = jObject.Deserialize(); + var crsType = token.GetString(); - if (converted.Properties != null) + if (string.Equals("name", crsType, StringComparison.OrdinalIgnoreCase)) + { + if (jObject.TryGetProperty("properties", out var properties)) { - foreach (var item in converted?.Properties) + var name = properties.GetProperty("name").GetString(); + + var target = new NamedCRS(name); + var converted = jObject.Deserialize(); + + if (converted.Properties != null) { - target.Properties[item.Key] = item.Value; + foreach (var item in converted?.Properties) + { + target.Properties[item.Key] = item.Value; + } } - } - return target; + return target; + } } - } - else if (string.Equals("link", crsType, StringComparison.OrdinalIgnoreCase)) - { - if (jObject.TryGetProperty("properties", out var properties)) + else if (string.Equals("link", crsType, StringComparison.OrdinalIgnoreCase)) { - var href = properties.GetProperty("href").GetString(); + if (jObject.TryGetProperty("properties", out var properties)) + { + var href = properties.GetProperty("href").GetString(); - var target = new LinkedCRS(href); + var target = new LinkedCRS(href); - var converted = jObject.Deserialize(); + var converted = jObject.Deserialize(); - if (converted.Properties != null) - { - foreach (var item in converted?.Properties) + if (converted.Properties != null) { - target.Properties[item.Key] = item.Value; + foreach (var item in converted?.Properties) + { + target.Properties[item.Key] = item.Value; + } } - } - return target; + return target; + } } - } - return new NotSupportedException(string.Format("Type {0} unexpected.", crsType)); - } - - /// - /// Writes the JSON representation of the object. - /// - /// The to write to. - /// The value. - /// The calling serializer. - /// - public override void Write(Utf8JsonWriter writer, object crsValue, JsonSerializerOptions options) - { - var value = (ICRSObject)crsValue; - - if (value == null) - return; + return new NotSupportedException(string.Format("Type {0} unexpected.", crsType)); + } - switch (value.Type) + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + /// + public override void Write( + Utf8JsonWriter writer, + object crsValue, + JsonSerializerOptions options) { - case CRSType.Name: - //var nameObject = (NamedCRS)value; - //var serializedName = JsonSerializer.Serialize(nameObject, options); - JsonSerializer.Serialize(writer, value, typeof(NamedCRS), options); - break; - case CRSType.Link: - //var linkedObject = (LinkedCRS)value; - //var serializedLink = JsonSerializer.Serialize(linkedObject, options); - //writer.WriteRawValue(serializedLink); - JsonSerializer.Serialize(writer, value, typeof(LinkedCRS), options); - break; - case CRSType.Unspecified: - writer.WriteNullValue(); - break; - default: - throw new ArgumentOutOfRangeException(); + var value = (ICRSObject)crsValue; + + if(value == null) + return; + + switch (value.Type) + { + case CRSType.Name: + //var nameObject = (NamedCRS)value; + //var serializedName = JsonSerializer.Serialize(nameObject, options); + JsonSerializer.Serialize(writer, value, typeof(NamedCRS), options); + break; + case CRSType.Link: + //var linkedObject = (LinkedCRS)value; + //var serializedLink = JsonSerializer.Serialize(linkedObject, options); + //writer.WriteRawValue(serializedLink); + JsonSerializer.Serialize(writer, value, typeof(LinkedCRS), options); + break; + case CRSType.Unspecified: + writer.WriteNullValue(); + break; + default: + throw new ArgumentOutOfRangeException(); + } } } } diff --git a/src/GeoJSON.Text/Converters/FeatureConverter.cs b/src/GeoJSON.Text/Converters/FeatureConverter.cs new file mode 100644 index 0000000..0532f33 --- /dev/null +++ b/src/GeoJSON.Text/Converters/FeatureConverter.cs @@ -0,0 +1,117 @@ +// Copyright © Joerg Battermann 2014, Matt Hunt 2017 + +using GeoJSON.Text.Feature; +using GeoJSON.Text.Geometry; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Converters +{ + /// + /// Converts types to and from JSON. + /// + public class FeatureConverter : JsonConverter + { + private static readonly GeometryConverter geometryConverter = new GeometryConverter(); + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) + { + return typeof(Feature.Feature).IsAssignableFromType(objectType) + || typeof(Feature.Feature<>).IsAssignableFromType(objectType) + || typeof(Feature.Feature<,>).IsAssignableFromType(objectType); + } + + public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var genericArguments = new Type[2]; + IGeometryObject geometryObject = null; + object properties = null; + string id = null; + if (reader.TokenType == JsonTokenType.StartObject) + { + var startDepth = reader.CurrentDepth; + while (reader.Read()) + { + if (JsonTokenType.EndObject == reader.TokenType && reader.CurrentDepth == startDepth) + { + if (genericArguments.Length == 0) + { + return new Feature.Feature(geometryObject, (IDictionary)properties, id); + } + else if (genericArguments.Length == 1) + { + var typedGeometry = Convert.ChangeType(geometryObject, genericArguments[0]); + return Activator.CreateInstance( + typeof(Feature<>).MakeGenericType( + genericArguments), + BindingFlags.Default, + binder: null, + args: new object[] { typedGeometry, (IDictionary)properties, id }, + culture: null); + } + else + { + var typedGeometry = Convert.ChangeType(geometryObject, genericArguments[0]); + var typedProperty = Convert.ChangeType(properties, genericArguments[1]); + return Activator.CreateInstance( + typeof(Feature<,>).MakeGenericType( + genericArguments), + BindingFlags.Default, + binder: null, + args: new object[] { typedGeometry, typedProperty, id }, + culture: null); + } + } + + if (reader.TokenType == JsonTokenType.PropertyName) + { + var propertyName = reader.GetString(); + genericArguments = typeToConvert.GetGenericArguments(); + if (propertyName == "geometry") + { + reader.Read(); //Move one step forward to get property value + geometryObject = (IGeometryObject)geometryConverter.Read(ref reader, typeof(IGeometryObject), options); + } + else if (propertyName == "properties") + { + if (genericArguments.Length > 1) + { + var typeOfProperties = typeToConvert.GetGenericArguments()[1]; // This is the argument for the property if set + properties = JsonSerializer.Deserialize(ref reader, typeOfProperties, options); + } + else + { + properties = JsonSerializer.Deserialize>(ref reader, options); + } + } + else if (propertyName == "id") + { + reader.Read(); //Move one step forward to get property value + id = reader.GetString(); + } + } + } + + throw new JsonException("End of object was not found"); + } + else + { + throw new JsonException("Json to parse of not of type object"); + } + } + + public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, options); + } + } +} \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/GeoJsonConverter.cs b/src/GeoJSON.Text/Converters/GeoJsonConverter.cs deleted file mode 100644 index 9cd7fd1..0000000 --- a/src/GeoJSON.Text/Converters/GeoJsonConverter.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright © Matt Hunt 2021 - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; -using GeoJSON.Net.Feature; -using GeoJSON.Net.Geometry; - -namespace GeoJSON.Net.Converters -{ - /// - /// Converts types to and from JSON. - /// - public class GeoJsonConverter : JsonConverter - { - /// - /// Determines whether this instance can convert the specified object type. - /// - /// Type of the object. - /// - /// true if this instance can convert the specified object type; otherwise, false. - /// - public override bool CanConvert(Type objectType) - { - return typeof(IGeoJSONObject).IsAssignableFromType(objectType); - } - - /// - /// Reads the JSON representation of the object. - /// - /// The to read from. - /// Type of the object. - /// The existing value of object being read. - /// The calling serializer. - /// - /// The object value. - /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - switch (reader.TokenType) - { - case JsonToken.Null: - return null; - case JsonToken.StartObject: - var value = JObject.Load(reader); - return ReadGeoJson(value); - case JsonToken.StartArray: - var values = JArray.Load(reader); - var geometries = new List(values.Count); - geometries.AddRange(values.Cast().Select(ReadGeoJson)); - return geometries; - } - - throw new JsonReaderException("expected null, object or array token but received " + reader.TokenType); - } - - /// - /// Writes the JSON representation of the object. - /// - /// The to write to. - /// The value. - /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - serializer.Serialize(writer, value); - } - - /// - /// Reads the geo json. - /// - /// The value. - /// - /// - /// json must contain a "type" property - /// or - /// type must be a valid geojson object type - /// - /// - /// Unknown geoJsonType {geoJsonType} - /// - private static IGeoJSONObject ReadGeoJson(JObject value) - { - JToken token; - - if (!value.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out token)) - { - throw new JsonReaderException("json must contain a \"type\" property"); - } - - GeoJSONObjectType geoJsonType; -#if (NET35) - try - { - geoJsonType = (GeoJSONObjectType)Enum.Parse(typeof(GeoJSONObjectType), token.Value(), true); - } - catch(Exception) - { - throw new JsonReaderException("Type must be a valid geojson object type"); - } -#else - if (!Enum.TryParse(token.Value(), true, out geoJsonType)) - { - throw new JsonReaderException("type must be a valid geojson object type"); - } -#endif - - switch (geoJsonType) - { - case GeoJSONObjectType.Point: - return value.ToObject(); - case GeoJSONObjectType.MultiPoint: - return value.ToObject(); - case GeoJSONObjectType.LineString: - return value.ToObject(); - case GeoJSONObjectType.MultiLineString: - return value.ToObject(); - case GeoJSONObjectType.Polygon: - return value.ToObject(); - case GeoJSONObjectType.MultiPolygon: - return value.ToObject(); - case GeoJSONObjectType.GeometryCollection: - return value.ToObject(); - case GeoJSONObjectType.Feature: - return value.ToObject(); - case GeoJSONObjectType.FeatureCollection: - return value.ToObject(); - default: - throw new NotSupportedException($"Unknown geoJsonType {geoJsonType}"); - } - } - } -} diff --git a/src/GeoJSON.Text/Converters/GeometryConverter.cs b/src/GeoJSON.Text/Converters/GeometryConverter.cs index b3b4fdd..621eeb7 100644 --- a/src/GeoJSON.Text/Converters/GeometryConverter.cs +++ b/src/GeoJSON.Text/Converters/GeometryConverter.cs @@ -1,22 +1,19 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Geometry; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// /// Converts types to and from JSON. /// - public class GeometryConverter : JsonConverter + public class GeometryConverter : JsonConverter { - public override bool CanWrite => false; - /// /// Determines whether this instance can convert the specified object type. /// @@ -39,35 +36,20 @@ public override bool CanConvert(Type objectType) /// /// The object value. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override IGeometryObject Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { switch (reader.TokenType) { - case JsonToken.Null: + case JsonTokenType.Null: return null; - case JsonToken.StartObject: - var value = JObject.Load(reader); - return ReadGeoJson(value); - case JsonToken.StartArray: - var values = JArray.Load(reader); - var geometries = new ReadOnlyCollection( - values.Cast().Select(ReadGeoJson).ToArray()); - return geometries; + case JsonTokenType.StartObject: + return ReadGeoJson(ref reader, options); } - throw new JsonReaderException("expected null, object or array token but received " + reader.TokenType); - } - - /// - /// Writes the JSON representation of the object. - /// - /// The to write to. - /// The value. - /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - // IGeometryObject can be written without a problem - throw new NotImplementedException("Unnecessary because CanWrite is false. The type will skip the converter."); + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); } /// @@ -83,54 +65,89 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s /// /// Feature and FeatureCollection types are Feature objects and not Geometry objects /// - private static IGeometryObject ReadGeoJson(JObject value) + private static IGeometryObject ReadGeoJson(ref Utf8JsonReader reader, JsonSerializerOptions options) { - JToken token; + var document = JsonDocument.ParseValue(ref reader); + JsonElement value = document.RootElement; + JsonElement token; - if (!value.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out token)) + if (!value.TryGetProperty("type", out token)) { - throw new JsonReaderException("json must contain a \"type\" property"); + throw new JsonException("json must contain a \"type\" property"); } GeoJSONObjectType geoJsonType; -#if (NET35) - try - { - geoJsonType = (GeoJSONObjectType)Enum.Parse(typeof(GeoJSONObjectType), token.Value(), true); - } - catch (Exception) + if (!Enum.TryParse(token.GetString(), true, out geoJsonType)) { - throw new JsonReaderException("Type must be a valid geojson object type"); + throw new JsonException("type must be a valid geojson geometry object type"); } -#else - if (!Enum.TryParse(token.Value(), true, out geoJsonType)) + + switch (geoJsonType) { - throw new JsonReaderException("type must be a valid geojson geometry object type"); + + case GeoJSONObjectType.Point: + return value.Deserialize(options); + case GeoJSONObjectType.MultiPoint: + return value.Deserialize(options); + case GeoJSONObjectType.LineString: + return value.Deserialize(options); + case GeoJSONObjectType.MultiLineString: + return value.Deserialize(options); + case GeoJSONObjectType.Polygon: + return value.Deserialize(options); + case GeoJSONObjectType.MultiPolygon: + return value.Deserialize(options); + case GeoJSONObjectType.GeometryCollection: + return value.Deserialize(options); + case GeoJSONObjectType.Feature: + case GeoJSONObjectType.FeatureCollection: + default: + throw new NotSupportedException("Feature and FeatureCollection types are Feature objects and not Geometry objects"); } -#endif + } - switch (geoJsonType) + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + public override void Write( + Utf8JsonWriter writer, + IGeometryObject value, + JsonSerializerOptions options) + { + // Standard serialization + switch (value.Type) { case GeoJSONObjectType.Point: - return value.ToObject(); + JsonSerializer.Serialize(writer, (Point)value); + break; case GeoJSONObjectType.MultiPoint: - return value.ToObject(); + JsonSerializer.Serialize(writer, (MultiPoint)value); + break; case GeoJSONObjectType.LineString: - return value.ToObject(); + JsonSerializer.Serialize(writer, (LineString)value); + break; case GeoJSONObjectType.MultiLineString: - return value.ToObject(); + JsonSerializer.Serialize(writer, (MultiLineString)value); + break; case GeoJSONObjectType.Polygon: - return value.ToObject(); + JsonSerializer.Serialize(writer, (Polygon)value); + break; case GeoJSONObjectType.MultiPolygon: - return value.ToObject(); + JsonSerializer.Serialize(writer, (MultiPolygon)value); + break; case GeoJSONObjectType.GeometryCollection: - return value.ToObject(); + JsonSerializer.Serialize(writer, (GeometryCollection)value); + break; case GeoJSONObjectType.Feature: case GeoJSONObjectType.FeatureCollection: default: throw new NotSupportedException("Feature and FeatureCollection types are Feature objects and not Geometry objects"); } } + } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/GeometryEnumerableConverter.cs b/src/GeoJSON.Text/Converters/GeometryEnumerableConverter.cs new file mode 100644 index 0000000..c77d12d --- /dev/null +++ b/src/GeoJSON.Text/Converters/GeometryEnumerableConverter.cs @@ -0,0 +1,93 @@ +// Copyright © Joerg Battermann 2014, Matt Hunt 2017 + +using GeoJSON.Text.Geometry; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Converters +{ + /// + /// Converts types to and from JSON. + /// + public class GeometryEnumerableConverter : JsonConverter> + { + private static readonly GeometryConverter GeometryConverter = new GeometryConverter(); + + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) + { + return typeof(ReadOnlyCollection).IsAssignableFromType(objectType); + } + + /// + /// Reads the JSON representation of the object. + /// + /// The to read from. + /// Type of the object. + /// The existing value of object being read. + /// The calling serializer. + /// + /// The object value. + /// + public override ReadOnlyCollection Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + case JsonTokenType.StartArray: + break; + } + + var startDepth = reader.CurrentDepth; + var result = new List(); + while (reader.Read()) + { + if (JsonTokenType.EndArray == reader.TokenType && reader.CurrentDepth == startDepth) + { + return new ReadOnlyCollection(result); + } + if (reader.TokenType == JsonTokenType.StartObject) + { + result.Add((IGeometryObject)GeometryConverter.Read( + ref reader, + typeof(IEnumerable), + options)); + } + } + + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); + } + + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + public override void Write( + Utf8JsonWriter writer, + ReadOnlyCollection value, + JsonSerializerOptions options) + { + writer.WriteStartArray(); + foreach(var item in value) + { + GeometryConverter.Write(writer, item, options); + } + writer.WriteEndArray(); + } + } +} \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs b/src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs new file mode 100644 index 0000000..5dcc4b2 --- /dev/null +++ b/src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Converters +{ + public class JsonStringEnumEnumMemberConverter : JsonConverterFactory + { + private readonly JsonNamingPolicy namingPolicy; + private readonly bool allowIntegerValues; + private readonly JsonStringEnumConverter baseConverter; + + public JsonStringEnumEnumMemberConverter() : this(null, true) { } + + public JsonStringEnumEnumMemberConverter(JsonNamingPolicy namingPolicy = null, bool allowIntegerValues = true) + { + this.namingPolicy = namingPolicy; + this.allowIntegerValues = allowIntegerValues; + this.baseConverter = new JsonStringEnumConverter(namingPolicy, allowIntegerValues); + } + + public override bool CanConvert(Type typeToConvert) => baseConverter.CanConvert(typeToConvert); + + public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) + { + var query = from field in typeToConvert.GetFields(BindingFlags.Public | BindingFlags.Static) + let attr = field.GetCustomAttribute() + where attr != null + select (field.Name, attr.Value); + var dictionary = query.ToDictionary(p => p.Item1, p => p.Item2); + if (dictionary.Count > 0) + { + return new JsonStringEnumConverter(new DictionaryLookupNamingPolicy(dictionary, namingPolicy), allowIntegerValues).CreateConverter(typeToConvert, options); + } + else + { + return baseConverter.CreateConverter(typeToConvert, options); + } + } + } + + public class JsonNamingPolicyDecorator : JsonNamingPolicy + { + readonly JsonNamingPolicy underlyingNamingPolicy; + + public JsonNamingPolicyDecorator(JsonNamingPolicy underlyingNamingPolicy) => this.underlyingNamingPolicy = underlyingNamingPolicy; + + public override string ConvertName(string name) => underlyingNamingPolicy == null ? name : underlyingNamingPolicy.ConvertName(name); + } + + internal class DictionaryLookupNamingPolicy : JsonNamingPolicyDecorator + { + readonly Dictionary dictionary; + + public DictionaryLookupNamingPolicy(Dictionary dictionary, JsonNamingPolicy underlyingNamingPolicy) : base(underlyingNamingPolicy) => this.dictionary = dictionary ?? throw new ArgumentNullException(); + + public override string ConvertName(string name) => dictionary.TryGetValue(name, out var value) ? value : base.ConvertName(name); + } +} \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs b/src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs index af6f9a8..fadf278 100644 --- a/src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs +++ b/src/GeoJSON.Text/Converters/LineStringEnumerableConverter.cs @@ -1,18 +1,18 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Geometry; using System; using System.Collections.Generic; -using System.Linq; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// - /// Converter to read and write the type. + /// Converter to read and write the type. /// - public class LineStringEnumerableConverter : JsonConverter + public class LineStringEnumerableConverter : JsonConverter> { private static readonly PositionEnumerableConverter LineStringConverter = new PositionEnumerableConverter(); @@ -25,7 +25,7 @@ public class LineStringEnumerableConverter : JsonConverter /// public override bool CanConvert(Type objectType) { - return typeof(IEnumerable).IsAssignableFromType(objectType); + return typeof(IReadOnlyCollection).IsAssignableFromType(objectType); } /// @@ -38,38 +38,58 @@ public override bool CanConvert(Type objectType) /// /// The object value. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override IReadOnlyCollection Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { - var rings = existingValue as JArray ?? serializer.Deserialize(reader); - return rings.Select(ring => new LineString((IEnumerable) LineStringConverter.ReadJson( - reader, - typeof(IEnumerable), - ring, - serializer))) - .ToArray(); + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + case JsonTokenType.StartArray: + break; + default: + throw new InvalidOperationException("Incorrect json type"); + } + + var startDepth = reader.CurrentDepth; + var result = new List(); + while (reader.Read()) + { + if(JsonTokenType.EndArray == reader.TokenType && reader.CurrentDepth == startDepth) + { + return new ReadOnlyCollection(result); + } + if(reader.TokenType == JsonTokenType.StartArray) + { + result.Add(new LineString(LineStringConverter.Read( + ref reader, + typeof(IEnumerable), + options))); + } + } + + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); } /// /// Writes the JSON representation of the object. /// - /// The to write to. + /// The to write to. /// The value. /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void Write( + Utf8JsonWriter writer, + IReadOnlyCollection value, + JsonSerializerOptions options) { - if (value is IEnumerable coordinateElements) - { - writer.WriteStartArray(); - foreach (var subPolygon in coordinateElements) - { - LineStringConverter.WriteJson(writer, subPolygon.Coordinates, serializer); - } - writer.WriteEndArray(); - } - else + writer.WriteStartArray(); + foreach (var subPolygon in value) { - throw new ArgumentException($"{nameof(LineStringEnumerableConverter)}: unsupported value type"); + LineStringConverter.Write(writer, subPolygon.Coordinates, options); } + writer.WriteEndArray(); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/PointEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PointEnumerableConverter.cs index 63dbb57..b2f146f 100644 --- a/src/GeoJSON.Text/Converters/PointEnumerableConverter.cs +++ b/src/GeoJSON.Text/Converters/PointEnumerableConverter.cs @@ -1,49 +1,80 @@ // Copyright � Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Geometry; using System; using System.Collections.Generic; -using System.Linq; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// /// Converter to read and write the type. /// - public class PointEnumerableConverter : JsonConverter + public class PointEnumerableConverter : JsonConverter> { private static readonly PositionConverter PositionConverter = new PositionConverter(); /// - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void Write( + Utf8JsonWriter writer, + ReadOnlyCollection value, + JsonSerializerOptions options) { - if (value is IEnumerable points) + writer.WriteStartArray(); + foreach (var point in value) { - writer.WriteStartArray(); - foreach (var point in points) - { - PositionConverter.WriteJson(writer, point.Coordinates, serializer); - } - writer.WriteEndArray(); - } - else - { - throw new ArgumentException($"{nameof(PointEnumerableConverter)}: unsupported value {value}"); + PositionConverter.Write(writer, point.Coordinates, options); } + writer.WriteEndArray(); } /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override ReadOnlyCollection Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { - var coordinates = existingValue as JArray ?? serializer.Deserialize(reader); - return coordinates.Select(position => new Point(position.ToObject>().ToPosition())); + switch (reader.TokenType) + { + // This converter has to read something starting with an array + case JsonTokenType.StartArray: + break; + case JsonTokenType.Null: + return null; + default: + throw new InvalidOperationException("Incorrect json type"); + } + + var startDepth = reader.CurrentDepth; + var result = new List(); + List numbers = new List(); + while (reader.Read()) + { + if (JsonTokenType.EndArray == reader.TokenType && reader.CurrentDepth == startDepth) + { + return new ReadOnlyCollection(result); + } + if(JsonTokenType.EndArray == reader.TokenType) + { + result.Add(new Point(numbers.ToPosition())); + + // We have finished reading this internal point array, clear so we can read next (If needed) + numbers.Clear(); + } + if(reader.TokenType == JsonTokenType.Number) + { + numbers.Add(reader.GetDouble()); + } + } + + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); } /// public override bool CanConvert(Type objectType) { - return objectType == typeof(IEnumerable); + return objectType == typeof(ReadOnlyCollection); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs index 733de15..79fdcc6 100644 --- a/src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs +++ b/src/GeoJSON.Text/Converters/PolygonEnumerableConverter.cs @@ -1,20 +1,23 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Geometry; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Linq; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// /// Converter to read and write the type. /// - public class PolygonEnumerableConverter : JsonConverter + public class PolygonEnumerableConverter : JsonConverter> { - + private static readonly LineStringEnumerableConverter PolygonConverter = new LineStringEnumerableConverter(); /// /// Determines whether this instance can convert the specified object type. @@ -25,7 +28,7 @@ public class PolygonEnumerableConverter : JsonConverter /// public override bool CanConvert(Type objectType) { - return objectType == typeof(IEnumerable); + return true || typeof(IReadOnlyCollection).IsAssignableFromType(objectType); } /// @@ -38,19 +41,40 @@ public override bool CanConvert(Type objectType) /// /// The object value. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override IReadOnlyCollection Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { - var o = serializer.Deserialize(reader); - var polygons = - o.Select( - polygonObject => (IEnumerable) PolygonConverter.ReadJson( - polygonObject.CreateReader(), - typeof(IEnumerable), - polygonObject, serializer)) - .Select(lines => new Polygon(lines)) - .ToList(); - return polygons; + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + case JsonTokenType.StartArray: + break; + default: + throw new InvalidOperationException("Incorrect json type"); + } + + var startDepth = reader.CurrentDepth; + var result = new List(); + while (reader.Read()) + { + if (JsonTokenType.EndArray == reader.TokenType && reader.CurrentDepth == startDepth) + { + return new ReadOnlyCollection(result); + } + if (reader.TokenType == JsonTokenType.StartArray) + { + result.Add(new Polygon(PolygonConverter.Read( + ref reader, + typeof(IEnumerable), + options))); + } + } + + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); } /// @@ -59,21 +83,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// The to write to. /// The value. /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void Write( + Utf8JsonWriter writer, + IReadOnlyCollection value, + JsonSerializerOptions options) { - if (value is IEnumerable polygons) - { - writer.WriteStartArray(); - foreach (var polygon in polygons) - { - PolygonConverter.WriteJson(writer, polygon.Coordinates, serializer); - } - writer.WriteEndArray(); - } - else + writer.WriteStartArray(); + foreach (var polygon in value) { - throw new ArgumentException($"{nameof(PointEnumerableConverter)}: unsupported value {value}"); + PolygonConverter.Write(writer, polygon.Coordinates, options); } + writer.WriteEndArray(); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/PositionConverter.cs b/src/GeoJSON.Text/Converters/PositionConverter.cs index 053d717..fc78e4f 100644 --- a/src/GeoJSON.Text/Converters/PositionConverter.cs +++ b/src/GeoJSON.Text/Converters/PositionConverter.cs @@ -1,16 +1,17 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Geometry; using System; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// /// Converter to read and write an , that is, /// the coordinates of a . /// - public class PositionConverter : JsonConverter + public class PositionConverter : JsonConverter { /// /// Determines whether this instance can convert the specified object type. @@ -34,19 +35,22 @@ public override bool CanConvert(Type objectType) /// /// The object value. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override IPosition Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { double[] coordinates; try { - coordinates = serializer.Deserialize(reader); + coordinates = JsonSerializer.Deserialize(ref reader); } catch (Exception e) { - throw new JsonReaderException("error parsing coordinates", e); + throw new JsonException("Error parsing coordinates", e); } - return coordinates?.ToPosition() ?? throw new JsonReaderException("coordinates cannot be null"); + return coordinates?.ToPosition() ?? throw new JsonException("Coordinates cannot be null"); } /// @@ -55,26 +59,22 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// The to write to. /// The value. /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void Write( + Utf8JsonWriter writer, + IPosition coordinates, + JsonSerializerOptions options) { - if (value is IPosition coordinates) - { - writer.WriteStartArray(); - - writer.WriteValue(coordinates.Longitude); - writer.WriteValue(coordinates.Latitude); + writer.WriteStartArray(); - if (coordinates.Altitude.HasValue) - { - writer.WriteValue(coordinates.Altitude.Value); - } + writer.WriteNumberValue(coordinates.Longitude); + writer.WriteNumberValue(coordinates.Latitude); - writer.WriteEndArray(); - } - else + if (coordinates.Altitude.HasValue) { - throw new NotImplementedException(); + writer.WriteNumberValue(coordinates.Altitude.Value); } + + writer.WriteEndArray(); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs b/src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs index c5cd53f..8218086 100644 --- a/src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs +++ b/src/GeoJSON.Text/Converters/PositionEnumerableConverter.cs @@ -2,20 +2,23 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Linq; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Geometry; -namespace GeoJSON.Net.Converters +namespace GeoJSON.Text.Converters { /// - /// Converter to read and write the type. + /// Converter to read and write the type. /// - public class PositionEnumerableConverter : JsonConverter + public class PositionEnumerableConverter : JsonConverter> { private static readonly PositionConverter PositionConverter = new PositionConverter(); - + /// /// Determines whether this instance can convert the specified object type. /// @@ -25,7 +28,7 @@ public class PositionEnumerableConverter : JsonConverter /// public override bool CanConvert(Type objectType) { - return typeof(IEnumerable).IsAssignableFromType(objectType); + return typeof(IReadOnlyCollection).IsAssignableFromType(objectType); } /// @@ -38,14 +41,39 @@ public override bool CanConvert(Type objectType) /// /// The object value. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override IReadOnlyCollection Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options) { - var coordinates = existingValue as JArray ?? serializer.Deserialize(reader); - return coordinates.Select(pos => PositionConverter.ReadJson(pos.CreateReader(), - typeof(IPosition), - pos, - serializer - )).Cast(); + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + case JsonTokenType.StartArray: + break; + default: + throw new InvalidOperationException("Incorrect json type"); + } + + var startDepth = reader.CurrentDepth; + var result = new List(); + while (reader.Read()) + { + if (JsonTokenType.EndArray == reader.TokenType && reader.CurrentDepth == startDepth) + { + return new ReadOnlyCollection(result); + } + if (reader.TokenType == JsonTokenType.StartArray) + { + result.Add(PositionConverter.Read( + ref reader, + typeof(IPosition), + options)); + } + } + + throw new JsonException($"expected null, object or array token but received {reader.TokenType}"); } /// @@ -54,21 +82,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist /// The to write to. /// The value. /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void Write( + Utf8JsonWriter writer, + IReadOnlyCollection coordinateElements, + JsonSerializerOptions options) { - if (value is IEnumerable coordinateElements) - { - writer.WriteStartArray(); - foreach (var position in coordinateElements) - { - PositionConverter.WriteJson(writer, position, serializer); - } - writer.WriteEndArray(); - } - else + writer.WriteStartArray(); + foreach (var position in coordinateElements) { - throw new ArgumentException($"{nameof(PositionEnumerableConverter)}: unsupported value type"); + PositionConverter.Write(writer, position, options); } + writer.WriteEndArray(); } } } \ No newline at end of file diff --git a/src/GeoJSON.Text/Converters/TypeExtensions.cs b/src/GeoJSON.Text/Converters/TypeExtensions.cs index f44a2af..c7c468b 100644 --- a/src/GeoJSON.Text/Converters/TypeExtensions.cs +++ b/src/GeoJSON.Text/Converters/TypeExtensions.cs @@ -1,9 +1,8 @@ -#if (!NET35 || !NET40) -using System; +using System; using System.Reflection; -#endif -namespace GeoJSON.Net.Converters + +namespace GeoJSON.Text.Converters { public static class TypeExtensions { @@ -12,11 +11,7 @@ public static class TypeExtensions /// public static bool IsAssignableFromType(this Type self, Type other) { -#if (NET35 || NET40) - return self.IsAssignableFrom(other); -#else return self.GetTypeInfo().IsAssignableFrom(other.GetTypeInfo()); -#endif } } diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs index 9802af4..e9e64c7 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs @@ -1,29 +1,32 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Converters; using System; using System.Collections.Generic; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using System.Text.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// /// Base class for all IGeometryObject implementing types /// - [JsonObject(MemberSerialization.OptIn)] + [JsonConverter(typeof(CRSBaseRequiredPropertyConverter))] public abstract class CRSBase : IEqualityComparer, IEquatable { /// /// Gets the properties. /// - [JsonProperty(PropertyName = "properties", Required = Required.Always)] + [JsonPropertyName("properties" )] + //Required = Required.Always)] public Dictionary Properties { get; internal set; } /// /// Gets the type of the GeometryObject object. /// - [JsonProperty(PropertyName = "type", Required = Required.Always)] - [JsonConverter(typeof(StringEnumConverter))] + [JsonPropertyName("type")] + //, Required = Required.Always)] + [JsonConverter(typeof(JsonStringEnumEnumMemberConverter))] public CRSType Type { get; internal set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs index abfad2e..64dc11c 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSType.cs @@ -1,8 +1,9 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 using System.Runtime.Serialization; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// /// Defines the GeoJSON Coordinate Reference System Objects (CRS) types as originally defined in the geojson.org v1.0 spec diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs index 2f9682a..8753eae 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/DefaultCRS.cs @@ -1,6 +1,6 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// /// The default CRS is a geographic coordinate reference system, diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs index a4058d8..1417ced 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/ICRSObject.cs @@ -1,6 +1,6 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// /// Base Interface for CRSBase Object types. diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs index 32fe391..4e666c9 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/LinkedCRS.cs @@ -3,18 +3,23 @@ using System; using System.Collections.Generic; -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// /// Defines the Linked CRS type. /// /// /// This was originally defined in the spec http://geojson.org/geojson-spec.html#named-crs - /// The current RFC removes the CRS type, but allows to be left in for backwards compatibility. + /// The current RFC removes the CRS type, but allows to be left in for backwards compatibility. /// See https://tools.ietf.org/html/rfc7946#section-4 /// public class LinkedCRS : CRSBase, ICRSObject { + public LinkedCRS() + { + + } + /// /// Initializes a new instance of the class. /// diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs index f717358..6a8c80f 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/NamedCRS.cs @@ -3,10 +3,10 @@ using System; using System.Collections.Generic; -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// - /// Defines the Named CRS type. + /// Defines the Named CRS type. /// /// /// See http://geojson.org/geojson-spec.html#named-crs @@ -15,6 +15,11 @@ namespace GeoJSON.Net.CoordinateReferenceSystem /// public class NamedCRS : CRSBase, ICRSObject { + public NamedCRS() + { + + } + /// /// Initializes a new instance of the class. /// diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs index 8e84406..cd91b1d 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/UnspecifiedCRS.cs @@ -1,13 +1,18 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net.CoordinateReferenceSystem +namespace GeoJSON.Text.CoordinateReferenceSystem { /// - /// Represents an unspecified Coordinate Reference System + /// Represents an unspecified Coordinate Reference System /// i.e. where a geojson object has a null crs /// public class UnspecifiedCRS : ICRSObject { + public UnspecifiedCRS() + { + + } + /// /// Gets the CRS type. /// diff --git a/src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs b/src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs index b484179..dbe75c5 100644 --- a/src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs +++ b/src/GeoJSON.Text/DoubleTenDecimalPlaceComparer.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace GeoJSON.Net +namespace GeoJSON.Text { /// /// Compares doubles for equality. diff --git a/src/GeoJSON.Text/Feature/Feature.cs b/src/GeoJSON.Text/Feature/Feature.cs index 6c4553d..ada31c6 100644 --- a/src/GeoJSON.Text/Feature/Feature.cs +++ b/src/GeoJSON.Text/Feature/Feature.cs @@ -1,16 +1,15 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 using System.Collections.Generic; -#if (!NET35 || !NET40) using System.Reflection; using System.Linq; -#endif -using GeoJSON.Net.Converters; -using GeoJSON.Net.Geometry; -using Newtonsoft.Json; +using GeoJSON.Text.Converters; +using GeoJSON.Text.Geometry; using System; +using System.Text.Json.Serialization; +using GeoJSON.Text.CoordinateReferenceSystem; -namespace GeoJSON.Net.Feature +namespace GeoJSON.Text.Feature { /// /// A GeoJSON Feature Object; generic version for strongly typed @@ -22,7 +21,18 @@ namespace GeoJSON.Net.Feature public class Feature : GeoJSONObject, IEquatable> where TGeometry : IGeometryObject { - [JsonConstructor] + private string _id; + private bool _idHasValue = false; + private TGeometry _geometry; + private bool _geometryHasValue = false; + private TProps _properties; + private bool _propertiesHasValue = false; + + public Feature() + { + + } + public Feature(TGeometry geometry, TProps properties, string id = null) { Geometry = geometry; @@ -30,25 +40,102 @@ public Feature(TGeometry geometry, TProps properties, string id = null) Id = id; } + public Feature(IGeometryObject geometry, TProps properties, string id = null) + { + Geometry = (TGeometry)geometry; + Properties = properties; + Id = id; + } + + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.Feature; - - [JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Ignore)] - public string Id { get; } - - [JsonProperty(PropertyName = "geometry", Required = Required.AllowNull)] + + [JsonPropertyName( "id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Id { + get + { + return _id; + } +#if NET5_0_OR_GREATER + init + { + if (_idHasValue) throw new InvalidOperationException("Id property already set, is read only"); + + _id = value; + _idHasValue = true; + } +#else + set + { + if (_idHasValue) throw new InvalidOperationException("Id property already set, is read only"); + + _id = value; + _idHasValue = true; + } +#endif + } + + [JsonPropertyName("geometry")] [JsonConverter(typeof(GeometryConverter))] - public TGeometry Geometry { get; } - - [JsonProperty(PropertyName = "properties", Required = Required.AllowNull)] - public TProps Properties { get; } - + public TGeometry Geometry { + get + { + return _geometry; + } +#if NET5_0_OR_GREATER + init + { + if (_geometryHasValue) throw new InvalidOperationException("Geometry property already set, is read only"); + + _geometry = value; + _geometryHasValue = true; + } +#else + set + { + if (_geometryHasValue) throw new InvalidOperationException("Geometry property already set, is read only"); + + _geometry = value; + _geometryHasValue = true; + } +#endif + } + + [JsonPropertyName("properties")] + public TProps Properties { + get + { + return _properties; + } +#if NET5_0_OR_GREATER + init + { + if (_propertiesHasValue) throw new InvalidOperationException("Geometry property already set, is read only"); + + _properties = value; + _propertiesHasValue = true; + } +#else + set + { + if (_propertiesHasValue) throw new InvalidOperationException("Geometry property already set, is read only"); + + _properties = value; + _propertiesHasValue = true; + } +#endif + } + /// /// Equality comparer. /// /// /// In contrast to , this implementation returns true only /// if and are also equal. See - /// #80 for discussion. The rationale + /// #80 for discussion. The rationale /// here is that a user explicitly specifying the property type most probably cares about the properties /// equality. /// @@ -94,8 +181,8 @@ public override int GetHashCode() return !object.Equals(left, right); } } - - + + /// /// A GeoJSON Feature Object. /// @@ -104,13 +191,17 @@ public override int GetHashCode() /// public class Feature : Feature { - [JsonConstructor] - public Feature(IGeometryObject geometry, IDictionary properties = null, string id = null) + public Feature() + { + + } + + public Feature(IGeometryObject geometry, IDictionary properties = null, string id = null) : base(geometry, properties, id) { } - public Feature(IGeometryObject geometry, object properties, string id = null) + public Feature(IGeometryObject geometry, object properties, string id = null) : base(geometry, properties, id) { } @@ -124,6 +215,10 @@ public Feature(IGeometryObject geometry, object properties, string id = null) /// public class Feature : Feature>, IEquatable> where TGeometry : IGeometryObject { + public Feature() + { + + } /// /// Initializes a new instance of the class. @@ -131,12 +226,22 @@ public class Feature : Feature /// The Geometry Object. /// The properties. /// The (optional) identifier. - [JsonConstructor] public Feature(TGeometry geometry, IDictionary properties = null, string id = null) : base(geometry, properties ?? new Dictionary(), id) { } + /// + /// Initializes a new instance of the class. + /// + /// The Geometry Object. + /// The properties. + /// The (optional) identifier. + public Feature(IGeometryObject geometry, IDictionary properties = null, string id = null) + : base((TGeometry)geometry, properties ?? new Dictionary(), id) + { + } + /// /// Initializes a new instance of the class. /// @@ -151,23 +256,17 @@ public Feature(TGeometry geometry, object properties, string id = null) { } + private static Dictionary GetDictionaryOfPublicProperties(object properties) { if (properties == null) { return new Dictionary(); } -#if(NET35 || NET40) - return properties.GetType().GetProperties() - .Where(propertyInfo => propertyInfo.GetGetMethod().IsPublic) - .ToDictionary(propertyInfo => propertyInfo.Name, - propertyInfo => propertyInfo.GetValue(properties, null)); -#else return properties.GetType().GetTypeInfo().DeclaredProperties .Where(propertyInfo => propertyInfo.GetMethod.IsPublic) .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(properties, null)); -#endif } public bool Equals(Feature other) diff --git a/src/GeoJSON.Text/Feature/FeatureCollection.cs b/src/GeoJSON.Text/Feature/FeatureCollection.cs index a1db797..15923a3 100644 --- a/src/GeoJSON.Text/Feature/FeatureCollection.cs +++ b/src/GeoJSON.Text/Feature/FeatureCollection.cs @@ -1,11 +1,12 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Converters; using System; using System.Collections.Generic; -using Newtonsoft.Json; using System.Linq; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Feature +namespace GeoJSON.Text.Feature { /// /// Defines the FeatureCollection type. @@ -33,14 +34,18 @@ public FeatureCollection(List features) Features = features; } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.FeatureCollection; /// /// Gets the features. /// /// The features. - [JsonProperty(PropertyName = "features", Required = Required.Always)] - public List Features { get; private set; } + [JsonPropertyName("features")] + //[JsonConverter(typeof(FeatureEnumerableConverter))] + public List Features { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/GeoJSON.Text.csproj b/src/GeoJSON.Text/GeoJSON.Text.csproj index d4561df..5271c72 100644 --- a/src/GeoJSON.Text/GeoJSON.Text.csproj +++ b/src/GeoJSON.Text/GeoJSON.Text.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net461; + netcoreapp3.1;net5;net6 Latest .Net types for the GeoJSON RFC to be used with System.Text.Json Matt Hunt diff --git a/src/GeoJSON.Text/GeoJSONObject.cs b/src/GeoJSON.Text/GeoJSONObject.cs index 3fa454a..899f3b7 100644 --- a/src/GeoJSON.Text/GeoJSONObject.cs +++ b/src/GeoJSON.Text/GeoJSONObject.cs @@ -1,20 +1,18 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -using System.Linq; -using System.Runtime.Serialization; -using GeoJSON.Net.Converters; -using GeoJSON.Net.CoordinateReferenceSystem; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using System.Collections.Generic; +using GeoJSON.Text.Converters; +using GeoJSON.Text.CoordinateReferenceSystem; using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text.Json.Serialization; -namespace GeoJSON.Net +namespace GeoJSON.Text { /// /// Base class for all IGeometryObject implementing types /// - [JsonObject(MemberSerialization.OptIn)] public abstract class GeoJSONObject : IGeoJSONObject, IEqualityComparer, IEquatable { internal static readonly DoubleTenDecimalPlaceComparer DoubleComparer = new DoubleTenDecimalPlaceComparer(); @@ -31,7 +29,9 @@ public abstract class GeoJSONObject : IGeoJSONObject, IEqualityComparer - [JsonProperty(PropertyName = "bbox", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("bbox")] + [JsonConverter(typeof(BoundingBoxConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double[] BoundingBoxes { get; set; } /// @@ -44,22 +44,22 @@ public abstract class GeoJSONObject : IGeoJSONObject, IEqualityComparer /// The Coordinate Reference System Objects. /// - [JsonProperty(PropertyName = "crs", Required = Required.Default, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, - NullValueHandling = NullValueHandling.Include)] + [JsonPropertyName("crs")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonConverter(typeof(CrsConverter))] - //[DefaultValue(typeof(DefaultCRS), "")] public ICRSObject CRS { get; set; } /// /// The (mandatory) type of the /// GeoJSON Object. /// - [JsonProperty(PropertyName = "type", Required = Required.Always, DefaultValueHandling = DefaultValueHandling.Include)] - [JsonConverter(typeof(StringEnumConverter))] + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public abstract GeoJSONObjectType Type { get; } - #region IEqualityComparer, IEquatable +#region IEqualityComparer, IEquatable /// /// Determines whether the specified object is equal to the current object @@ -153,6 +153,6 @@ public int GetHashCode(GeoJSONObject obj) return obj.GetHashCode(); } - #endregion +#endregion } } \ No newline at end of file diff --git a/src/GeoJSON.Text/GeoJSONObjectType.cs b/src/GeoJSON.Text/GeoJSONObjectType.cs index f7a42ac..e7dd7dc 100644 --- a/src/GeoJSON.Text/GeoJSONObjectType.cs +++ b/src/GeoJSON.Text/GeoJSONObjectType.cs @@ -1,6 +1,8 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net +using System.Runtime.Serialization; + +namespace GeoJSON.Text { /// /// Defines the GeoJSON Objects types. @@ -13,6 +15,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.2 /// + [EnumMember(Value = "point")] Point, /// @@ -21,6 +24,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.3 /// + [EnumMember(Value = "multipoint")] MultiPoint, /// @@ -29,6 +33,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.4 /// + [EnumMember(Value = "linestring")] LineString, /// @@ -37,6 +42,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.5 /// + [EnumMember(Value = "point")] MultiLineString, /// @@ -44,7 +50,8 @@ public enum GeoJSONObjectType /// /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.6 - /// + /// + [EnumMember(Value = "point")] Polygon, /// @@ -53,6 +60,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.7 /// + [EnumMember(Value = "point")] MultiPolygon, /// @@ -61,6 +69,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.8 /// + [EnumMember(Value = "point")] GeometryCollection, /// @@ -69,6 +78,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.2 /// + [EnumMember(Value = "point")] Feature, /// @@ -77,6 +87,7 @@ public enum GeoJSONObjectType /// /// See https://tools.ietf.org/html/rfc7946#section-3.3 /// + [EnumMember(Value = "point")] FeatureCollection } } diff --git a/src/GeoJSON.Text/Geometry/GeometryCollection.cs b/src/GeoJSON.Text/Geometry/GeometryCollection.cs index 0b0fada..62fcb61 100644 --- a/src/GeoJSON.Text/Geometry/GeometryCollection.cs +++ b/src/GeoJSON.Text/Geometry/GeometryCollection.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Converters; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the GeometryCollection type. @@ -34,14 +34,17 @@ public GeometryCollection(IEnumerable geometries) geometries?.ToArray() ?? throw new ArgumentNullException(nameof(geometries))); } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.GeometryCollection; /// /// Gets the list of Polygons enclosed in this MultiPolygon. /// - [JsonProperty("geometries", Required = Required.Always)] - [JsonConverter(typeof(GeometryConverter))] - public ReadOnlyCollection Geometries { get; private set; } + [JsonPropertyName("geometries")] + [JsonConverter(typeof(GeometryEnumerableConverter))] + public ReadOnlyCollection Geometries { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/Geometry/IGeometryObject.cs b/src/GeoJSON.Text/Geometry/IGeometryObject.cs index 8235760..9fe7592 100644 --- a/src/GeoJSON.Text/Geometry/IGeometryObject.cs +++ b/src/GeoJSON.Text/Geometry/IGeometryObject.cs @@ -1,15 +1,19 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net.Geometry +using GeoJSON.Text.Converters; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text.Geometry { /// /// Base Interface for GeometryObject types. /// + [JsonConverter(typeof(GeometryConverter))] public interface IGeometryObject { /// /// Gets the (mandatory) type of the GeoJSON Object. - /// However, for GeoJSON Objects only the 'Point', 'MultiPoint', 'LineString', 'MultiLineString', + /// However, for GeoJSON Objects only the 'Point', 'MultiPoint', 'LineString', 'MultiLineString', /// 'Polygon', 'MultiPolygon', or 'GeometryCollection' types are allowed. /// /// @@ -18,6 +22,8 @@ public interface IGeometryObject /// /// The type of the object. /// + [JsonPropertyName("type")] + [JsonConverter(typeof(JsonStringEnumConverter))] GeoJSONObjectType Type { get; } } } diff --git a/src/GeoJSON.Text/Geometry/IPosition.cs b/src/GeoJSON.Text/Geometry/IPosition.cs index f133f10..118ae52 100644 --- a/src/GeoJSON.Text/Geometry/IPosition.cs +++ b/src/GeoJSON.Text/Geometry/IPosition.cs @@ -1,5 +1,5 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the Geographic Position type. @@ -13,7 +13,7 @@ public interface IPosition /// Gets the altitude. /// double? Altitude { get; } - + /// /// Gets the latitude. /// diff --git a/src/GeoJSON.Text/Geometry/LineString.cs b/src/GeoJSON.Text/Geometry/LineString.cs index 7197bba..f7db77a 100644 --- a/src/GeoJSON.Text/Geometry/LineString.cs +++ b/src/GeoJSON.Text/Geometry/LineString.cs @@ -1,13 +1,13 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 +using GeoJSON.Text.Converters; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the LineString type. @@ -15,14 +15,18 @@ namespace GeoJSON.Net.Geometry /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.4 /// - [JsonObject(MemberSerialization.OptIn)] public class LineString : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public LineString() + { + + } + /// /// Initializes a new from a 2-d array of s /// that matches the "coordinates" field in the JSON representation. /// - [JsonConstructor] + //[JsonConstructor] public LineString(IEnumerable> coordinates) : this(coordinates?.Select(latLongAlt => (IPosition)latLongAlt.ToPosition()) ?? throw new ArgumentException(nameof(coordinates))) @@ -46,14 +50,17 @@ public LineString(IEnumerable coordinates) } } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.LineString; /// /// The positions of the line string. /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] [JsonConverter(typeof(PositionEnumerableConverter))] - public ReadOnlyCollection Coordinates { get; } + public ReadOnlyCollection Coordinates { get; set; } /// /// Determines whether this instance has its first and last coordinate at the same position and thereby is closed. diff --git a/src/GeoJSON.Text/Geometry/MultiLineString.cs b/src/GeoJSON.Text/Geometry/MultiLineString.cs index 4d10885..170badd 100644 --- a/src/GeoJSON.Text/Geometry/MultiLineString.cs +++ b/src/GeoJSON.Text/Geometry/MultiLineString.cs @@ -1,15 +1,15 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -using System.Collections.Generic; -using System.Linq; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using GeoJSON.Text.Converters; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { - + /// /// Defines the MultiLineString type. /// @@ -18,6 +18,11 @@ namespace GeoJSON.Net.Geometry /// public class MultiLineString : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public MultiLineString() + { + + } + /// /// Initializes a new instance of the class. /// @@ -32,21 +37,24 @@ public MultiLineString(IEnumerable coordinates) /// Initializes a new from a 3-d array /// of s that matches the "coordinates" field in the JSON representation. /// - [JsonConstructor] + //[JsonConstructor] public MultiLineString(IEnumerable>> coordinates) : this(coordinates?.Select(line => new LineString(line)) ?? throw new ArgumentNullException(nameof(coordinates))) { } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.MultiLineString; /// /// The collection of line strings of this . /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] [JsonConverter(typeof(LineStringEnumerableConverter))] - public ReadOnlyCollection Coordinates { get; } + public ReadOnlyCollection Coordinates { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/Geometry/MultiPoint.cs b/src/GeoJSON.Text/Geometry/MultiPoint.cs index d49df7a..059f9fe 100644 --- a/src/GeoJSON.Text/Geometry/MultiPoint.cs +++ b/src/GeoJSON.Text/Geometry/MultiPoint.cs @@ -1,13 +1,13 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; +using GeoJSON.Text.Converters; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; -using GeoJSON.Net.Converters; +using System.Linq; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Contains an array of . @@ -17,6 +17,11 @@ namespace GeoJSON.Net.Geometry /// public class MultiPoint : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public MultiPoint() + { + + } + /// /// Initializes a new instance of the class. /// @@ -25,22 +30,25 @@ public MultiPoint(IEnumerable coordinates) { Coordinates = new ReadOnlyCollection(coordinates?.ToArray() ?? new Point[0]); } - - [JsonConstructor] + + //[JsonConstructor] public MultiPoint(IEnumerable> coordinates) : this(coordinates?.Select(position => new Point(position.ToPosition())) ?? throw new ArgumentNullException(nameof(coordinates))) { } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.MultiPoint; /// /// The points contained in this . /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] [JsonConverter(typeof(PointEnumerableConverter))] - public ReadOnlyCollection Coordinates { get; } + public ReadOnlyCollection Coordinates { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/Geometry/MultiPolygon.cs b/src/GeoJSON.Text/Geometry/MultiPolygon.cs index 706bfe6..3c9b261 100644 --- a/src/GeoJSON.Text/Geometry/MultiPolygon.cs +++ b/src/GeoJSON.Text/Geometry/MultiPolygon.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Converters; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the MultiPolygon type. @@ -17,6 +17,7 @@ namespace GeoJSON.Net.Geometry /// public class MultiPolygon : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public MultiPolygon() { } /// /// Initializes a new instance of the class. @@ -32,21 +33,24 @@ public MultiPolygon(IEnumerable polygons) /// Initializes a new from a 4-d array of s /// that matches the "coordinates" field in the JSON representation. /// - [JsonConstructor] + // [JsonConstructor] public MultiPolygon(IEnumerable>>> coordinates) : this(coordinates?.Select(polygon => new Polygon(polygon)) ?? throw new ArgumentNullException(nameof(coordinates))) { } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.MultiPolygon; /// /// The list of Polygons enclosed in this . /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] [JsonConverter(typeof(PolygonEnumerableConverter))] - public ReadOnlyCollection Coordinates { get; } + public ReadOnlyCollection Coordinates { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/Geometry/Point.cs b/src/GeoJSON.Text/Geometry/Point.cs index 05d7286..19724a0 100644 --- a/src/GeoJSON.Text/Geometry/Point.cs +++ b/src/GeoJSON.Text/Geometry/Point.cs @@ -1,11 +1,11 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 using System; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using GeoJSON.Text.Converters; using System.Collections.Generic; +using System.Text.Json.Serialization; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the Point type. @@ -16,6 +16,9 @@ namespace GeoJSON.Net.Geometry /// public class Point : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public Point() + { + } /// /// Initializes a new instance of the class. @@ -26,14 +29,18 @@ public Point(IPosition coordinates) Coordinates = coordinates ?? throw new ArgumentNullException(nameof(coordinates)); } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.Point; /// /// The underlying this point. /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonConverter(typeof(PositionConverter))] - public IPosition Coordinates { get; } + public IPosition Coordinates { get; set; } #region IEqualityComparer, IEquatable @@ -88,7 +95,7 @@ public bool Equals(Point left, Point right) { return !(left == right); } - + /// /// Returns the hash code for this instance /// diff --git a/src/GeoJSON.Text/Geometry/Polygon.cs b/src/GeoJSON.Text/Geometry/Polygon.cs index 3e30f48..6c78a53 100644 --- a/src/GeoJSON.Text/Geometry/Polygon.cs +++ b/src/GeoJSON.Text/Geometry/Polygon.cs @@ -4,14 +4,14 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using GeoJSON.Net.Converters; -using Newtonsoft.Json; +using System.Text.Json.Serialization; +using GeoJSON.Text.Converters; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// Defines the Polygon type. - /// Coordinates of a Polygon are a list of linear rings coordinate arrays. The first element in + /// Coordinates of a Polygon are a list of linear rings coordinate arrays. The first element in /// the array represents the exterior ring. Any subsequent elements represent interior rings (or holes). /// /// @@ -19,11 +19,16 @@ namespace GeoJSON.Net.Geometry /// public class Polygon : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { + public Polygon() + { + + } + /// /// Initializes a new instance of the class. /// /// - /// The linear rings with the first element in the array representing the exterior ring. + /// The linear rings with the first element in the array representing the exterior ring. /// Any subsequent elements represent interior rings (or holes). /// public Polygon(IEnumerable coordinates) @@ -36,28 +41,31 @@ public Polygon(IEnumerable coordinates) " (see GeoJSON spec at 'https://tools.ietf.org/html/rfc7946#section-3.1.6').", nameof(coordinates)); } - + } /// /// Initializes a new from a 3-d array of s /// that matches the "coordinates" field in the JSON representation. /// - [JsonConstructor] + //[JsonConstructor] public Polygon(IEnumerable>> coordinates) : this(coordinates?.Select(line => new LineString(line)) ?? throw new ArgumentNullException(nameof(coordinates))) { } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [JsonConverter(typeof(JsonStringEnumConverter))] public override GeoJSONObjectType Type => GeoJSONObjectType.Polygon; /// /// Gets the list of linestrings defining this . /// - [JsonProperty("coordinates", Required = Required.Always)] + [JsonPropertyName("coordinates")] [JsonConverter(typeof(LineStringEnumerableConverter))] - public ReadOnlyCollection Coordinates { get; } + public ReadOnlyCollection Coordinates { get; set; } #region IEqualityComparer, IEquatable diff --git a/src/GeoJSON.Text/Geometry/Position.cs b/src/GeoJSON.Text/Geometry/Position.cs index 0228980..a27704a 100644 --- a/src/GeoJSON.Text/Geometry/Position.cs +++ b/src/GeoJSON.Text/Geometry/Position.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Globalization; -namespace GeoJSON.Net.Geometry +namespace GeoJSON.Text.Geometry { /// /// A position is the fundamental geometry construct, consisting of , @@ -70,7 +70,7 @@ public Position(string latitude, string longitude, string altitude = null) Altitude = alt; } } - + /// /// Gets the altitude. /// @@ -85,7 +85,7 @@ public Position(string latitude, string longitude, string altitude = null) /// Gets the longitude or X coordinate /// public double Longitude { get; } - + /// /// Returns a that represents this instance. /// diff --git a/src/GeoJSON.Text/IGeoJSONObject.cs b/src/GeoJSON.Text/IGeoJSONObject.cs index 78400ef..35436f2 100644 --- a/src/GeoJSON.Text/IGeoJSONObject.cs +++ b/src/GeoJSON.Text/IGeoJSONObject.cs @@ -1,6 +1,9 @@ // Copyright © Joerg Battermann 2014, Matt Hunt 2017 -namespace GeoJSON.Net +using GeoJSON.Text.Converters; +using System.Text.Json.Serialization; + +namespace GeoJSON.Text { /// /// Base Interface for GeoJSONObject types. @@ -16,6 +19,7 @@ public interface IGeoJSONObject /// /// The type of the object. /// + [JsonPropertyName("type")] GeoJSONObjectType Type { get; } /// @@ -27,6 +31,7 @@ public interface IGeoJSONObject /// /// The Coordinate Reference System Objects. /// + [JsonPropertyName("crs")] CoordinateReferenceSystem.ICRSObject CRS { get; } /// @@ -42,6 +47,8 @@ public interface IGeoJSONObject /// In addition, the coordinate reference system for the bbox is assumed to match the coordinate reference /// system of the GeoJSON object of which it is a member. /// + [JsonPropertyName("bbox")] + [JsonConverter(typeof(BoundingBoxConverter))] double[] BoundingBoxes { get; set; } } } diff --git a/src/GeoJSON.Text/PositionExtensions.cs b/src/GeoJSON.Text/PositionExtensions.cs index 32ccad8..fb87868 100644 --- a/src/GeoJSON.Text/PositionExtensions.cs +++ b/src/GeoJSON.Text/PositionExtensions.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using GeoJSON.Net.Geometry; +using GeoJSON.Text.Geometry; -namespace GeoJSON.Net +namespace GeoJSON.Text { internal static class PositionExtensions { diff --git a/src/GeoJSON.Text/Settings.StyleCop b/src/GeoJSON.Text/Settings.StyleCop index 79022b4..b2f078b 100644 --- a/src/GeoJSON.Text/Settings.StyleCop +++ b/src/GeoJSON.Text/Settings.StyleCop @@ -2,7 +2,7 @@ - GeoJSON.Net + GeoJSON.Text Copyright © Jörg Battermann 2011, Matt Hunt 2017 From b1fd9319987c52006912419e38649b47b12de4c7 Mon Sep 17 00:00:00 2001 From: Martin Carpentier Date: Thu, 16 Dec 2021 20:57:50 +0100 Subject: [PATCH 3/6] Updated the ci file --- .github/workflows/ci-build.yml | 74 +++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index c5af9d2..9ef4130 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -1,27 +1,73 @@ -name: Build and Tests +name: 'Build and Test' on: push: - branches: [ main ] pull_request: branches: [ main ] jobs: - build: + Build: + + runs-on: ubuntu-latest + env: + VSTEST_CONNECTION_TIMEOUT: 900 + strategy: + matrix: + dotnet-version: [ 'netcoreapp3.1', 'net5', 'net6' ] + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0.x' + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + - name: Install dependencies + run: dotnet restore ./src/ + - name: Build solution + run: dotnet build ./src/ --no-restore --framework ${{matrix.dotnet-version}} + + Test: + needs: build runs-on: ubuntu-latest env: VSTEST_CONNECTION_TIMEOUT: 900 + strategy: + matrix: + dotnet-version: [ 'netcoreapp3.1', 'net5', 'net6' ] + + if: success() steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '6.0.x' - - name: Install dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test - run: dotnet test --no-restore --verbosity normal + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0.x' + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + - name: Install dependencies + run: dotnet restore ./src/ + - name: Test with dotnet + run: dotnet test ./src/ --framework ${{matrix.dotnet-version}} --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" + - name: Upload dotnet test results + uses: actions/upload-artifact@v2 + with: + name: dotnet-results-${{ matrix.dotnet-version }} + path: TestResults-${{ matrix.dotnet-version }} + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} \ No newline at end of file From c4d97638ee1d44b29ff7e1cd6302436d0b6f48ef Mon Sep 17 00:00:00 2001 From: Matt Lethargic Date: Sat, 18 Dec 2021 00:23:40 +0000 Subject: [PATCH 4/6] Adding CI changes with code cov --- .github/workflows/ci-build.yml | 70 +++++++++------------------------- .gitignore | 3 ++ README.md | 5 +++ 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 9ef4130..b898155 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -9,65 +9,31 @@ jobs: Build: runs-on: ubuntu-latest - env: - VSTEST_CONNECTION_TIMEOUT: 900 + defaults: + run: + working-directory: ./src - strategy: - matrix: - dotnet-version: [ 'netcoreapp3.1', 'net5', 'net6' ] - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '5.0.x' - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '6.0.x' - - name: Install dependencies - run: dotnet restore ./src/ - - name: Build solution - run: dotnet build ./src/ --no-restore --framework ${{matrix.dotnet-version}} - - Test: - needs: build - runs-on: ubuntu-latest env: VSTEST_CONNECTION_TIMEOUT: 900 - - strategy: - matrix: - dotnet-version: [ 'netcoreapp3.1', 'net5', 'net6' ] - if: success() steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '5.0.x' + - uses: actions/checkout@v2 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0.x' + dotnet-version: | + 3.1.x + 5.0.x + 6.0.x - name: Install dependencies - run: dotnet restore ./src/ - - name: Test with dotnet - run: dotnet test ./src/ --framework ${{matrix.dotnet-version}} --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" - - name: Upload dotnet test results - uses: actions/upload-artifact@v2 + run: dotnet restore + - name: Build solution + run: dotnet build -c Release --no-restore /p:Version=1.2.3.4 + - name: Test + run: dotnet test -c Release --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=../coverage/ + - uses: codecov/codecov-action@v2 with: - name: dotnet-results-${{ matrix.dotnet-version }} - path: TestResults-${{ matrix.dotnet-version }} - # Use always() to always run this step to publish test results when there are test failures - if: ${{ always() }} \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} + directory: ../coverage/ + flags: unittests + \ No newline at end of file diff --git a/.gitignore b/.gitignore index dfcfd56..c03ee55 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,6 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + + +*.opencover.xml \ No newline at end of file diff --git a/README.md b/README.md index a251176..04654b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ +[![Build and Test](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml/badge.svg?branch=main)](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml) +(http://img.shields.io/nuget/v/GeoJSON.Text.svg?style=flat)](https://www.nuget.org/packages/GeoJSON.Text/) +[![codecov](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text/branch/main/graph/badge.svg?token=SE9XY1T8XO)](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text) + + # GetJson.Text .Net library for GeoJSON types & corresponding System.TExt.Json (de)serializers From e237799aff0eed36a99df3d96612301b86a85a26 Mon Sep 17 00:00:00 2001 From: Matt Lethargic Date: Sat, 18 Dec 2021 00:27:52 +0000 Subject: [PATCH 5/6] changing readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 04654b6..165683c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -[![Build and Test](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml/badge.svg?branch=main)](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml) -(http://img.shields.io/nuget/v/GeoJSON.Text.svg?style=flat)](https://www.nuget.org/packages/GeoJSON.Text/) -[![codecov](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text/branch/main/graph/badge.svg?token=SE9XY1T8XO)](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text) +[![Build and Test](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml/badge.svg?branch=main)](https://github.com/GeoJSON-Net/GeoJSON.Text/actions/workflows/ci-build.yml) [![codecov](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text/branch/main/graph/badge.svg?token=SE9XY1T8XO)](https://codecov.io/gh/GeoJSON-Net/GeoJSON.Text) # GetJson.Text From 98165f246852e1881fcf6bf5fcde4ed953a6a32e Mon Sep 17 00:00:00 2001 From: Matt Lethargic Date: Sat, 18 Dec 2021 13:50:31 +0000 Subject: [PATCH 6/6] renaming converter --- src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj | 8 ++++++++ ...emberConverter.cs => JsonStringEnumMemberConverter.cs} | 8 ++++---- src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) rename src/GeoJSON.Text/Converters/{JsonStringEnumEnumMemberConverter.cs => JsonStringEnumMemberConverter.cs} (88%) diff --git a/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj b/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj index 83ad7c3..581ae1c 100644 --- a/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj +++ b/src/GeoJSON.Text.Tests/GeoJSON.Text.Tests.csproj @@ -58,6 +58,14 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs b/src/GeoJSON.Text/Converters/JsonStringEnumMemberConverter.cs similarity index 88% rename from src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs rename to src/GeoJSON.Text/Converters/JsonStringEnumMemberConverter.cs index 5dcc4b2..4def10f 100644 --- a/src/GeoJSON.Text/Converters/JsonStringEnumEnumMemberConverter.cs +++ b/src/GeoJSON.Text/Converters/JsonStringEnumMemberConverter.cs @@ -8,15 +8,15 @@ namespace GeoJSON.Text.Converters { - public class JsonStringEnumEnumMemberConverter : JsonConverterFactory + public class JsonStringEnumMemberConverter : JsonConverterFactory { private readonly JsonNamingPolicy namingPolicy; private readonly bool allowIntegerValues; private readonly JsonStringEnumConverter baseConverter; - public JsonStringEnumEnumMemberConverter() : this(null, true) { } + public JsonStringEnumMemberConverter() : this(null, true) { } - public JsonStringEnumEnumMemberConverter(JsonNamingPolicy namingPolicy = null, bool allowIntegerValues = true) + public JsonStringEnumMemberConverter(JsonNamingPolicy namingPolicy = null, bool allowIntegerValues = true) { this.namingPolicy = namingPolicy; this.allowIntegerValues = allowIntegerValues; @@ -43,7 +43,7 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer } } - public class JsonNamingPolicyDecorator : JsonNamingPolicy + internal class JsonNamingPolicyDecorator : JsonNamingPolicy { readonly JsonNamingPolicy underlyingNamingPolicy; diff --git a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs index e9e64c7..1d269c1 100644 --- a/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs +++ b/src/GeoJSON.Text/CoordinateReferenceSystem/CRSBase.cs @@ -26,7 +26,7 @@ public abstract class CRSBase : IEqualityComparer, IEquatable /// [JsonPropertyName("type")] //, Required = Required.Always)] - [JsonConverter(typeof(JsonStringEnumEnumMemberConverter))] + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public CRSType Type { get; internal set; } #region IEqualityComparer, IEquatable