FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: GeographicPosition serialization · LiveEarthSoftware/GeoJSON.Net@7ab400c · GitHub

Repository navigation

Commit 7ab400c

Browse files
committed
Fix: GeographicPosition serialization
1 parent a510f73 commit 7ab400c

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Serialization;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
9+
namespace GeoJSON.Net.Tests
10+
{
11+
[TestClass]
12+
public class DeserializationTest
13+
{
14+
15+
}
16+
}

‎src/GeoJSON.Net.Tests/GeoJSON.Net.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
</Reference>
4747
</ItemGroup>
4848
<ItemGroup>
49+
<Compile Include="DeserializationTest.cs" />
4950
<Compile Include="MiscTest.cs" />
5051
<Compile Include="Properties\AssemblyInfo.cs" />
5152
<Compile Include="SerializationTest.cs" />

‎src/GeoJSON.Net.Tests/SerializationTest.cs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ public void PolygonSerialization()
4242
Assert.IsTrue(!serializedData.Contains("latitude"));
4343
}
4444

45+
[TestMethod]
46+
public void GeographicPositionSerialization()
47+
{
48+
var model = new GeoJSON.Net.Geometry.GeographicPosition(112.12, 10);
49+
50+
var serialized = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
51+
52+
var matches = Regex.Matches(serialized, @"(\d+.\d+)");
53+
Assert.IsTrue(matches.Count == 2);
54+
double lng= 0;
55+
double.TryParse(matches[0].Value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out lng);
56+
57+
Assert.AreEqual(lng, 112.12);
58+
}
59+
60+
4561
[TestMethod]
4662
public void PolygonDeserialization()
4763
{
@@ -146,10 +162,8 @@ public void PointDeserialization()
146162

147163
Assert.IsTrue(coordinates.Longitude - 165.3173828125 < 0.0001);
148164
Assert.IsTrue(coordinates.Latitude + 52.379790828551016 < 0.0001);
149-
150165
}
151166

152-
153167
[TestMethod]
154168
public void PointFeatureDeserialization()
155169
{

‎src/GeoJSON.Net/Geometry/IPosition.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Newtonsoft.Json;
22
namespace GeoJSON.Net.Geometry
33
{
4-
[JsonArray]
4+
//[JsonArray]
55
public interface IPosition
66
{
77
}

‎src/GeoJSON.Net/Geometry/Point.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public Point(IPosition coordinates)
4747

4848
[JsonProperty(PropertyName = "coordinates", Required = Required.Always)]
4949
[JsonConverter(typeof(PointConverter))]
50-
5150
public IPosition Coordinates { get; set; }
5251
}
5352
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL