Skip to content

Commit 15b64b7

Browse files
supermihimatt-lethargic
authored andcommitted
Don't touch CRS on (de)serializing (#90)
Removes code that creates a default CRS on deserializing when JSON contains None, and that removes an existing default CRS when serializing. According to https://tools.ietf.org/html/rfc7946#section-4, the CRS shouldn't be specified anyway, so it's not a good idea to create one whenever deserializing a CRS-less JSON object.
1 parent b65fe86 commit 15b64b7

File tree

2 files changed

+1
-68
lines changed

2 files changed

+1
-68
lines changed

src/GeoJSON.Net.Tests/CoordinateReferenceSystem/DefaultCrsTests.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,8 @@ public void Can_Deserialize_When_Json_Does_Not_Contain_Crs_Property()
2626

2727
var point = JsonConvert.DeserializeObject<Point>(json);
2828

29-
Assert.IsInstanceOf<DefaultCRS>(point.CRS);
29+
Assert.IsNull(point.CRS);
3030
}
3131

32-
[Test]
33-
public void Equals_GetHashCode_Contract()
34-
{
35-
var json = "{\"coordinates\":[90.65464646,53.2455662,200.4567],\"type\":\"Point\"}";
36-
37-
var point = JsonConvert.DeserializeObject<Point>(json);
38-
39-
var expected = DefaultCRS.Instance;
40-
var actual = point.CRS;
41-
42-
Assert.AreEqual(expected, actual);
43-
44-
Assert.IsTrue(expected.Equals(actual));
45-
Assert.IsTrue(actual.Equals(expected));
46-
47-
Assert.IsTrue(actual.Equals(actual));
48-
Assert.IsTrue(expected.Equals(expected));
49-
50-
Assert.IsTrue(expected == actual);
51-
Assert.IsTrue(actual == expected);
52-
53-
Assert.AreEqual(expected.GetHashCode(), actual.GetHashCode());
54-
55-
}
5632
}
5733
}

src/GeoJSON.Net/GeoJSONObject.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public abstract class GeoJSONObject : IGeoJSONObject, IEqualityComparer<GeoJSONO
1919
{
2020
internal static readonly DoubleTenDecimalPlaceComparer DoubleComparer = new DoubleTenDecimalPlaceComparer();
2121

22-
protected GeoJSONObject()
23-
{
24-
CRS = DefaultCRS.Instance;
25-
}
26-
2722
/// <summary>
2823
/// Gets or sets the (optional)
2924
/// <see cref="https://tools.ietf.org/html/rfc7946#section-5">Bounding Boxes</see>.
@@ -63,44 +58,6 @@ protected GeoJSONObject()
6358
[JsonConverter(typeof(StringEnumConverter))]
6459
public abstract GeoJSONObjectType Type { get; }
6560

66-
/// <summary>
67-
/// Called when [deserialized].
68-
/// </summary>
69-
/// <param name="streamingContext">The streaming context.</param>
70-
[OnDeserialized]
71-
private void OnDeserialized(StreamingContext streamingContext)
72-
{
73-
if (CRS == null)
74-
{
75-
CRS = DefaultCRS.Instance;
76-
}
77-
}
78-
79-
/// <summary>
80-
/// Called when [serialized].
81-
/// </summary>
82-
/// <param name="streamingContext">The streaming context.</param>
83-
[OnSerialized]
84-
private void OnSerialized(StreamingContext streamingContext)
85-
{
86-
if (CRS == null)
87-
{
88-
CRS = DefaultCRS.Instance;
89-
}
90-
}
91-
92-
/// <summary>
93-
/// Called when [serializing].
94-
/// </summary>
95-
/// <param name="streamingContext">The streaming context.</param>
96-
[OnSerializing]
97-
private void OnSerializing(StreamingContext streamingContext)
98-
{
99-
if (CRS is DefaultCRS)
100-
{
101-
CRS = null;
102-
}
103-
}
10461

10562
#region IEqualityComparer, IEquatable
10663

0 commit comments

Comments
 (0)