Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-lethargic committed Oct 28, 2022
2 parents a7a828d + 84ed5d8 commit 8487224
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
34 changes: 34 additions & 0 deletions src/GeoJSON.Net.Tests/Serialization/JsonTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using GeoJSON.Net.Converters;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
using NUnit.Framework;

namespace GeoJSON.Net.Tests.Serialization
{
public class JsonTests
{
[Test]
public void Can_Serialize_as_GeoJSONObject()
{
GeoJSONObject source = new Point(new Position(10, 20));

var json = JsonConvert.SerializeObject(source, new GeoJsonConverter());

var deserialized = JsonConvert.DeserializeObject<GeoJSONObject>(json, new GeoJsonConverter());

Assert.AreEqual(source, deserialized);
}

[Test]
public void Can_Serialize_as_IGeoJSONObject()
{
IGeoJSONObject source = new Point(new Position(10, 20));

var json = JsonConvert.SerializeObject(source, new GeoJsonConverter());

var deserialized = JsonConvert.DeserializeObject<IGeoJSONObject>(json, new GeoJsonConverter());

Assert.AreEqual(source, deserialized);
}
}
}
21 changes: 12 additions & 9 deletions src/GeoJSON.Net/Converters/GeoJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ namespace GeoJSON.Net.Converters
/// </summary>
public class GeoJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <returns>
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
/// </returns>
public override bool CanConvert(Type objectType)
/// <inheritdoc/>
public override bool CanWrite => false;

/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <returns>
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
/// </returns>
public override bool CanConvert(Type objectType)
{
return typeof(IGeoJSONObject).IsAssignableFromType(objectType);
}
Expand Down Expand Up @@ -64,7 +67,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
throw new NotSupportedException();
}

/// <summary>
Expand Down

0 comments on commit 8487224

Please sign in to comment.