Skip to content

Commit

Permalink
This should fix it... needs a test or three, though.
Browse files Browse the repository at this point in the history
  • Loading branch information
airbreather committed Apr 24, 2024
1 parent 68b0bb1 commit 4892284
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override FeatureCollection Read(ref Utf8JsonReader reader, Type objectTyp
else
{
reader.ReadOrThrow();
reader.Skip();
reader.SkipOrThrow();
reader.ReadOrThrow();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public override IFeature Read(ref Utf8JsonReader reader, Type objectType, JsonSe

default:
// If property name is not one of the above: skip it entirely (foreign member)
reader.Skip();
reader.SkipOrThrow();
// Advance
while (reader.Read())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public override Geometry Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
break;
default: // included "bbox" property
//read, but can't do anything with it (see NetTopologySuite.IO.GeoJSON => NetTopologySuite.IO.Converters.GeometryConverter.ParseGeometry)
reader.Skip();
reader.SkipOrThrow();
reader.Read();
break;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ public override void Write(Utf8JsonWriter writer, Geometry value, JsonSerializer

private void WritePolygon(Utf8JsonWriter writer, Polygon value, JsonSerializerOptions options)
{

writer.WriteStartArray();
WriteCoordinateSequence(writer, value.ExteriorRing.CoordinateSequence, options, orientation:_oriExterior);
for (int i = 0; i < value.NumInteriorRings; i++)
Expand Down
13 changes: 13 additions & 0 deletions src/NetTopologySuite.IO.GeoJSON4STJ/Converters/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ internal static void AssertToken(this ref Utf8JsonReader reader, JsonTokenType r
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void SkipOrThrow(this ref Utf8JsonReader reader)
{
if (!reader.TrySkip())
{
ThrowForUnexpectedPartialJson();
}
}

internal static object ObjectFromJsonNode(JsonNode node, JsonSerializerOptions serializerOptions)
{
switch (node)
Expand Down Expand Up @@ -93,6 +102,10 @@ internal static JsonNode ObjectToJsonNode(object obj, JsonSerializerOptions seri
private static void ThrowForUnexpectedEndOfStream()
=> throw new JsonException(Resources.EX_UnexpectedEndOfStream);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowForUnexpectedPartialJson()
=> throw new JsonException(Resources.EX_UnexpectedPartialJson);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowForUnexpectedToken(JsonTokenType requiredNextTokenType, ref Utf8JsonReader reader)
=> throw new JsonException(string.Format(Resources.EX_UnexpectedToken, requiredNextTokenType, reader.TokenType, CurrentTokenAsString(in reader)));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@
<data name="EX_UnexpectedToken" xml:space="preserve">
<value>Expected token is '{0}' but was '{1}' (Value '{2}').</value>
</data>
</root>
<data name="EX_UnexpectedPartialJson" xml:space="preserve">
<value>JsonConverter received partial JSON. This is likely the result of a bug in the System.Text.Json library.</value>
</data>
</root>

0 comments on commit 4892284

Please sign in to comment.