Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to System.Text.Json #151

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
b8b0b45
chore: add system.text.json
steveoh Sep 2, 2020
74f2791
chore: replace JsonProperty with JsonPropertyName
steveoh Sep 2, 2020
7ef301f
chore: remove StringEnumConverter
steveoh Sep 2, 2020
ec5f0cc
chore: remove unnecessary opt in attribute
steveoh Sep 2, 2020
8f65a23
chore: remove JsonConstructor
steveoh Sep 2, 2020
e18d932
style: remove unnecessary white space
steveoh Sep 2, 2020
23608e4
chore: update line ending for cross plat development
steveoh Sep 2, 2020
6f058e0
chore: ignore mac trash
steveoh Sep 2, 2020
e4ce00d
chore: remove incompatible targets
steveoh Sep 2, 2020
5d91f87
chore: clean up unused usings
steveoh Sep 2, 2020
3d8d757
chore: remove signing for now
steveoh Sep 2, 2020
853dfd6
chore: use a v2 version value
steveoh Sep 2, 2020
af318b6
chore: remove unnecessary property name
steveoh Sep 3, 2020
c8d26be
wip: fool with converting the converters
steveoh Sep 3, 2020
beab99d
refactor: switch to STJ
steveoh Sep 3, 2020
b42f547
style: remove whitespace
steveoh Sep 3, 2020
13d486c
test: remove test warnings by updating project type and dependencies
steveoh Sep 3, 2020
5b775be
test: remove ifdef
steveoh Sep 3, 2020
170380b
feat: partial mplementation of geometry converter
steveoh Sep 3, 2020
12b166e
chore: remove converter as STJ isn't polymorphic
steveoh Sep 3, 2020
3b67bf0
fix: align coordinates as IReadOnlyCollection<IPosition>
steveoh Sep 3, 2020
c2f3413
style: replace with var
steveoh Sep 3, 2020
38da505
chore: update namespaces
steveoh Sep 3, 2020
cff2740
refactor: make converter do as little as possible
steveoh Sep 3, 2020
89da9ca
chore: convert to STJ serializer
steveoh Sep 3, 2020
69c6bdf
fix: align higher order geometries on IPosition
steveoh Sep 3, 2020
530980c
style: spelling and whitespace
steveoh Sep 3, 2020
2191c64
wip: remove imlementation
steveoh Sep 3, 2020
0b4a064
style: use var
steveoh Sep 3, 2020
d3657a8
chore: remove all newtonsoft references except for JsonAssert
steveoh Sep 3, 2020
9d19f0d
test: fix compilation
steveoh Sep 3, 2020
dfec342
test: fix point tests
steveoh Sep 3, 2020
56d4a45
chore: remove unnecessary naming policy
steveoh Sep 10, 2020
fda9240
chore: put back jsonconstructor
steveoh Sep 10, 2020
a050dc2
chore: put back converters
steveoh Sep 10, 2020
bc71be5
tests: linestring tests pass
steveoh Sep 10, 2020
02cfdf2
tests: polygon tests pass
steveoh Sep 10, 2020
2377db7
chore: remove unnecessary ctor assignments
steveoh Sep 10, 2020
6b4b4a5
fix: implement read/write methods of converter
steveoh Sep 10, 2020
04f0ff9
refactor: move coordinate creation to geometry type
steveoh Sep 10, 2020
540702b
chore: remove unused usings
steveoh Sep 10, 2020
6bc2485
refactor: use static read only converter
steveoh Sep 10, 2020
fb4fdd2
tests: multipoint tests passing
steveoh Sep 10, 2020
87619da
tests: multilinestring tests passing
steveoh Sep 10, 2020
63166a7
tests: multipolygon tests pass
steveoh Sep 10, 2020
800de58
style: use converter as name convention
steveoh Sep 10, 2020
6824811
style: remove whitespace
steveoh Sep 10, 2020
d7e3e85
tests: most geometry tests passing
steveoh Sep 10, 2020
980dedb
wip: this is over or under reading the json
steveoh Sep 10, 2020
25abb9c
chore: update to rc1
steveoh Sep 15, 2020
9479cf4
wip: latest changes
steveoh Sep 17, 2020
061f503
tests: fix overreading issue
steveoh Sep 17, 2020
c964bf6
test: pass default options
steveoh Sep 17, 2020
7583cc8
chore: modify target frameworks
steveoh Sep 17, 2020
35aa49e
wip: geometry converter sends a different index of the json object
steveoh Sep 17, 2020
05d013d
style: use var
steveoh Sep 21, 2020
c44139e
test: tostring object
steveoh Sep 21, 2020
27f3646
style: use var and remove unnecessary this.
steveoh Sep 21, 2020
4f32f10
test: add default serializer
steveoh Sep 21, 2020
9743941
chore: remove unused method
steveoh Sep 21, 2020
9985eb0
test: fix linestring test
steveoh Sep 21, 2020
7792000
test: fix geometrytests
steveoh Sep 21, 2020
2431fe6
tests: remove .0's from doubles
steveoh Sep 21, 2020
750c3dc
test: add default serializer settings
steveoh Sep 21, 2020
29933e5
fix: out of order reading failed remove it
steveoh Sep 21, 2020
37d4594
fix: let converters write the object
steveoh Sep 21, 2020
927c9c5
fix: always write type first
steveoh Sep 21, 2020
3e1b108
test: fix polygon in geometrycollection read
steveoh Sep 21, 2020
6219861
test: fix geometry collection serialization
steveoh Sep 21, 2020
2249fa4
test: fix feature tests
steveoh Sep 21, 2020
1adec57
test: stj does not try to guess type and dictionaries are objects
steveoh Sep 21, 2020
a60e22e
test: fix feature tests
steveoh Sep 21, 2020
414f47b
style: unify variable name and don't read too much
steveoh Sep 21, 2020
3e1f75c
test: feature collection tests pass
steveoh Sep 23, 2020
f1bb57c
fix: don't assume enum conversions
steveoh Sep 23, 2020
574b312
test: crs tests passing
steveoh Sep 23, 2020
45b0056
chore: use wildcard
steveoh Sep 23, 2020
b219469
fix: add crs to features
steveoh Sep 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,4 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml
.DS_Store
7 changes: 0 additions & 7 deletions src/Directory.Build.props

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GeoJSON.Net.CoordinateReferenceSystem;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Text.Json;

namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
{
Expand All @@ -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, DefaultSerializerOptions);

Assert.IsTrue(!json.Contains("\"crs\""));
}
Expand All @@ -24,7 +24,7 @@ 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<Point>(json);
var point = JsonSerializer.Deserialize<Point>(json, DefaultSerializerOptions);

Assert.IsNull(point.CRS);
}
Expand All @@ -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<Point>(json);
var point = JsonSerializer.Deserialize<Point>(json, DefaultSerializerOptions);

Assert.IsNotNull(point.CRS);
Assert.AreEqual(CRSType.Name, point.CRS.Type);
Expand All @@ -44,10 +44,10 @@ public void Can_Deserialize_CRS_issue_89()
public void Can_Serialize_CRS_issue_89()
{
var expected =
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"TEST NAME\"},\"type\":\"name\"}}";
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"TEST 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, DefaultSerializerOptions);

Assert.IsNotNull(json);
Assert.AreEqual(expected, json);
Expand All @@ -57,13 +57,13 @@ public void Can_Serialize_CRS_issue_89()
public void Can_Serialize_DefaultCRS_issue_89()
{
var expected =
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"urn:ogc:def:crs:OGC::CRS84\"},\"type\":\"name\"}}";
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"urn:ogc:def:crs:OGC::CRS84\"}}}";
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, DefaultSerializerOptions);

Assert.IsNotNull(json);
Assert.AreEqual(expected, json);
}
}
}
}
19 changes: 8 additions & 11 deletions src/GeoJSON.Net.Tests/CoordinateReferenceSystem/LinkedCRSTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using GeoJSON.Net.CoordinateReferenceSystem;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Text.Json;

namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
{
Expand Down Expand Up @@ -41,16 +41,16 @@ 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, DefaultSerializerOptions);

JsonAssert.Contains("{\"properties\":{\"href\":\"http://localhost\"},\"type\":\"link\"}", actualJson);
JsonAssert.Contains("{\"type\":\"link\",\"properties\":{\"href\":\"http://localhost\"}}", actualJson);
}

[Test]
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<Point>(pointJson);
const string pointJson = "{\"type\":\"Point\",\"coordinates\":[2.0,1.0,3.0],\"crs\":{\"type\":\"link\",\"properties\":{\"href\":\"http://localhost\"}}}";
var pointWithCRS = JsonSerializer.Deserialize<Point>(pointJson, DefaultSerializerOptions);
var linkCRS = pointWithCRS.CRS as LinkedCRS;

Assert.IsNotNull(linkCRS);
Expand All @@ -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

var argumentExpection = Assert.Throws<ArgumentException>(() => { var crs = new LinkedCRS("http://not-a-valid-<>-url"); });
Assert.AreEqual($"must be a dereferenceable URI{Environment.NewLine}Parameter name: href", argumentExpection.Message);

Assert.AreEqual($"must be a dereferenceable URI (Parameter 'href')", argumentExpection.Message);
}

[Test]
Expand Down Expand Up @@ -127,4 +124,4 @@ public void Equals_GetHashCode_Contract()
Assert.AreNotEqual(left.GetHashCode(), right.GetHashCode());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using GeoJSON.Net.CoordinateReferenceSystem;
using GeoJSON.Net.Feature;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Text.Json;

namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
{
Expand Down Expand Up @@ -32,9 +32,9 @@ 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, DefaultSerializerOptions);

JsonAssert.Contains("{\"properties\":{\"name\":\"EPSG:31370\"},\"type\":\"name\"}", actualJson);
JsonAssert.Contains("\"type\":\"name\",\"properties\":{\"name\":\"EPSG:31370\"}", actualJson);
}

[Test]
Expand Down Expand Up @@ -84,4 +84,4 @@ public void Equals_GetHashCode_Contract()
Assert.AreNotEqual(left.GetHashCode(), right.GetHashCode());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GeoJSON.Net.CoordinateReferenceSystem;
using GeoJSON.Net.Feature;
using Newtonsoft.Json;
using System.Text.Json;
using NUnit.Framework;

namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
Expand All @@ -21,16 +21,16 @@ 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, DefaultSerializerOptions);

JsonAssert.AreEqual(expectedJson, actualJson);
}

[Test]
public void Can_Deserialize_From_Null()
{
var json = "{\"type\":\"FeatureCollection\",\"crs\":null,\"features\":[] }";
var featureCollection = JsonConvert.DeserializeObject<FeatureCollection>(json);
var featureCollection = JsonSerializer.Deserialize<FeatureCollection>(json, DefaultSerializerOptions);

Assert.IsInstanceOf<UnspecifiedCRS>(featureCollection.CRS);
}
Expand All @@ -55,4 +55,4 @@ public void Equals_GetHashCode_Contract()
Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
}
}
}
}
26 changes: 12 additions & 14 deletions src/GeoJSON.Net.Tests/Feature/FeatureCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
using System.Text.Json;
using NUnit.Framework;

namespace GeoJSON.Net.Tests.Feature
Expand All @@ -23,12 +23,12 @@ public void Ctor_Throws_ArgumentNullException_When_Features_Is_Null()
[Test]
public void Can_Deserialize()
{
string json = GetExpectedJson();
var json = GetExpectedJson();

var featureCollection = JsonConvert.DeserializeObject<FeatureCollection>(json);
var featureCollection = JsonSerializer.Deserialize<FeatureCollection>(json, DefaultSerializerOptions);

Assert.IsNotNull(featureCollection.Features);
Assert.AreEqual(featureCollection.Features.Count, 3);
Assert.AreEqual(3, featureCollection.Features.Count);
Assert.AreEqual(featureCollection.Features.Count(x => x.Geometry.Type == GeoJSONObjectType.Point), 1);
Assert.AreEqual(featureCollection.Features.Count(x => x.Geometry.Type == GeoJSONObjectType.MultiPolygon), 1);
Assert.AreEqual(featureCollection.Features.Count(x => x.Geometry.Type == GeoJSONObjectType.Polygon), 1);
Expand Down Expand Up @@ -56,13 +56,13 @@ public void FeatureCollectionSerialization()
model.Features.Add(feature);
}

var actualJson = JsonConvert.SerializeObject(model);
var actualJson = JsonSerializer.Serialize<FeatureCollection>(model);

Assert.IsNotNull(actualJson);

Assert.IsFalse(string.IsNullOrEmpty(actualJson));
}

[Test]
public void FeatureCollection_Equals_GetHashCode_Contract()
{
Expand All @@ -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<FeatureCollection>(leftJson);
var leftJson = JsonSerializer.Serialize<FeatureCollection>(leftFc);
var left = JsonSerializer.Deserialize<FeatureCollection>(leftJson);

var rightFc = GetFeatureCollection();
var rightJson = JsonConvert.SerializeObject(rightFc);
var right = JsonConvert.DeserializeObject<FeatureCollection>(rightJson);
var rightJson = JsonSerializer.Serialize<FeatureCollection>(rightFc);
var right = JsonSerializer.Deserialize<FeatureCollection>(rightJson);

Assert_Are_Equal(left, right);
}
Expand Down Expand Up @@ -124,12 +124,10 @@ 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");

}

}


Expand Down Expand Up @@ -171,4 +169,4 @@ private void Assert_Are_Equal(FeatureCollection left, FeatureCollection right)
Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
"coordinates": [102, 0.5]
},
"properties": {
"prop0": "value0"
Expand Down Expand Up @@ -58,11 +58,11 @@
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
[100, 0],
[101, 0],
[101, 1],
[100, 1],
[100, 0]
]
]
},
Expand All @@ -73,4 +73,4 @@
}
}
}]
}
}
Loading