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

Don't use Serializer context #59

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -203,3 +203,4 @@ NetTopologySuite.Samples.Shapefiles/tmp*.shx
NetTopologySuite.Samples.Shapefiles/tmp*.dbf
NetTopologySuite.Samples.Shapefiles/test_arcview.shp
NetTopologySuite.Samples.Shapefiles/test_buffer.shp
.idea/
DGuidi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,10 @@ private static object InternalReadJson(JsonReader reader, JsonSerializer seriali
// Advance reader
reader.Read();
reader.SkipComments();

IAttributesTable attributesTable = null;
if (!innerObject && serializer.Context.Context is IFeature feature)
{
attributesTable = feature.Attributes;
}
var attributesTable = new AttributesTable();

if (reader.TokenType != JsonToken.Null)
{
if (attributesTable is null)
{
attributesTable = new AttributesTable();
}

while (reader.TokenType == JsonToken.PropertyName)
{
string attributeName = (string)reader.Value;
Expand Down
21 changes: 17 additions & 4 deletions src/NetTopologySuite.IO.GeoJSON/Converters/FeatureConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,23 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
throw new ArgumentException("Expected token '{' not found.");
}

var context = serializer.Context;
serializer.Context = new StreamingContext(serializer.Context.State, feature);
feature.Attributes = serializer.Deserialize<AttributesTable>(reader);
serializer.Context = context;
var attributes = serializer.Deserialize<AttributesTable>(reader);

if (feature.Attributes is null)
{
feature.Attributes = attributes;
}
else
{
foreach (var attribute in attributes)
{
if (!feature.Attributes.Exists(attribute.Key))
{
feature.Attributes.Add(attribute.Key, attribute.Value);
}
}
}

if (reader.TokenType != JsonToken.EndObject)
{
throw new ArgumentException("Expected token '}' not found.");
Expand Down