-
Notifications
You must be signed in to change notification settings - Fork 533
SpatialPoint Serialization/Deserialization: Fixes spatial point serialization/deserialization bug #4801
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
Open
dibahlfi
wants to merge
41
commits into
main
Choose a base branch
from
users/dikshibahl/SpatialPointSerializationBug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
SpatialPoint Serialization/Deserialization: Fixes spatial point serialization/deserialization bug #4801
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
968bcc8
SpatialPoint Serialization/Deserialization: Fixes spatial point seria…
dibahlfi bf9bb6e
SpatialPoint Serialization/Deserialization: Fixes spatial point seria…
dibahlfi 35b4846
WIP: STJ Serialization/DeSerialization
dibahlfi b3193f1
WIP: STJ Serialization/DeSerialization
dibahlfi 9cb6ccb
WIP: STJ Serialization/DeSerialization
dibahlfi 8564f03
WIP: STJ Serialization/DeSerialization
dibahlfi a3fca0c
WIP: STJ Serialization/DeSerialization
dibahlfi d38562a
WIP: STJ Serialization/DeSerialization
dibahlfi 036f213
WIP: STJ Serialization/DeSerialization
dibahlfi 3f62825
refactoring: matching STJ serialization/de format same as newtonsoft …
dibahlfi 922cea7
cleaning up
dibahlfi c33db60
cleaning up
dibahlfi d2c6015
cleaning up
dibahlfi 74a0aff
cleaning up
dibahlfi 6186e66
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician e02b884
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 7c2b5b7
Merge remote-tracking branch 'origin/master' into users/dikshibahl/Sp…
NaluTripician 03dde96
added comments for clarity and tests
NaluTripician 23eb888
test fixes
NaluTripician 12372b0
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 017e413
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 62c5ff1
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 2162340
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 3b996d4
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
kirankumarkolli 23e949d
[Internal/Ignore] Spatial Serialization: Fixes JsonElement.Deserializ…
Copilot 5416e55
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 7e5e11c
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician fa6c6e7
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician b9bbe65
Tests: Adds PatchItemAsync test case for spatial point serialization
NaluTripician 27852c5
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 06d999b
Tests: Fixes PatchOperation path in STJ spatial serialization test
NaluTripician 8600e02
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 46673e8
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician c7cff42
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 0e10fd3
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 9bcadcd
Address review feedback: use STJMetaDataFields constants and RMResources
NaluTripician 2bbcef2
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 1c597e8
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 0f21a4a
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 1acee99
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician 7e986f0
Merge branch 'master' into users/dikshibahl/SpatialPointSerializationBug
NaluTripician File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Microsoft.Azure.Cosmos/src/Spatial/Converters/STJConverters/BoundingBoxSTJConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Spatial.Converters.STJConverters | ||
| { | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Azure.Documents; | ||
| /// <summary> | ||
| /// Converter used to support System.Text.Json serialization/deserialization of BoundingBox. | ||
| /// </summary> | ||
| internal sealed class BoundingBoxSTJConverter : JsonConverter<BoundingBox> | ||
| { | ||
| /// <summary> | ||
| /// Deserializes a BoundingBox from a JSON array of coordinates. | ||
| /// The array contains min coordinates followed by max coordinates. | ||
| /// Example: [minLon, minLat, maxLon, maxLat] for 2D or [minLon, minLat, minAlt, maxLon, maxLat, maxAlt] for 3D. | ||
| /// </summary> | ||
| public override BoundingBox Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| double[] coordinates = JsonSerializer.Deserialize<double[]>(ref reader, options); | ||
| if (coordinates == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (coordinates.Length % 2 != 0 || coordinates.Length < 4) | ||
| { | ||
| throw new JsonException(RMResources.SpatialBoundingBoxInvalidCoordinates); | ||
| } | ||
|
|
||
| return new BoundingBox( | ||
| new Position(coordinates.Take(coordinates.Length / 2).ToList()), | ||
| new Position(coordinates.Skip(coordinates.Length / 2).ToList())); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Serializes a BoundingBox to a JSON array. | ||
| /// Outputs min coordinates followed by max coordinates. | ||
| /// </summary> | ||
| public override void Write(Utf8JsonWriter writer, BoundingBox box, JsonSerializerOptions options) | ||
| { | ||
| writer.WriteStartArray(); | ||
| foreach (double coordinate in box.Min.Coordinates.Concat(box.Max.Coordinates)) | ||
| { | ||
| // Check if the number is effectively an integer. | ||
| if (coordinate == Math.Truncate(coordinate)) | ||
| { | ||
| // If so, write it with one decimal place to match Newtonsoft's [x.0] format. | ||
| writer.WriteRawValue(coordinate.ToString("0.0", CultureInfo.InvariantCulture)); | ||
| } | ||
| else | ||
| { | ||
| writer.WriteRawValue(coordinate.ToString("R", CultureInfo.InvariantCulture)); | ||
| } | ||
| } | ||
| writer.WriteEndArray(); | ||
| } | ||
| } | ||
| } |
128 changes: 128 additions & 0 deletions
128
Microsoft.Azure.Cosmos/src/Spatial/Converters/STJConverters/CrsSTJConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Spatial.Converters.STJConverters | ||
| { | ||
| using System; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Azure.Documents; | ||
| /// <summary> | ||
| /// Converter used to support System.Text.Json serialization/deserialization of Crs (Coordinate Reference System). | ||
| /// Handles NamedCrs, LinkedCrs, and Unspecified CRS types. | ||
| /// Ensures output format matches Newtonsoft.Json exactly. | ||
| /// </summary> | ||
| internal sealed class CrsSTJConverter : JsonConverter<Crs> | ||
| { | ||
| public override bool HandleNull => true; | ||
|
|
||
| /// <summary> | ||
| /// Deserializes a CRS from JSON. | ||
| /// Supports named CRS (e.g., EPSG:4326) and linked CRS with optional type. | ||
| /// Returns Crs.Unspecified for null values. | ||
| /// </summary> | ||
| public override Crs Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.Null) | ||
| { | ||
| return Crs.Unspecified; | ||
| } | ||
|
|
||
| if (reader.TokenType != JsonTokenType.StartObject) | ||
| { | ||
| throw new JsonException(RMResources.JsonUnexpectedToken); | ||
| } | ||
|
|
||
| JsonElement rootElement = JsonDocument.ParseValue(ref reader).RootElement; | ||
| if (!rootElement.TryGetProperty(STJMetaDataFields.Properties, out JsonElement properties) || (properties.ValueKind != JsonValueKind.Object)) | ||
| { | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
|
|
||
| if (!rootElement.TryGetProperty(STJMetaDataFields.Type, out JsonElement crsType) || crsType.ValueKind != JsonValueKind.String) | ||
| { | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
|
|
||
| switch (crsType.GetString()) | ||
| { | ||
| case "name": | ||
| if (!properties.TryGetProperty(STJMetaDataFields.Name, out JsonElement crsName) || crsName.ValueKind != JsonValueKind.String) | ||
| { | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
| return new NamedCrs(crsName.GetString()); | ||
|
|
||
| case "link": | ||
| if (!properties.TryGetProperty(STJMetaDataFields.Href, out JsonElement crsHref) || crsHref.ValueKind != JsonValueKind.String) | ||
| { | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
|
|
||
| if (properties.TryGetProperty(STJMetaDataFields.Type, out JsonElement crsHrefType)) | ||
| { | ||
| if (crsHrefType.ValueKind != JsonValueKind.String) | ||
| { | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
| return new LinkedCrs(crsHref.GetString(), crsHrefType.GetString()); | ||
| } | ||
| return new LinkedCrs(crsHref.GetString()); | ||
|
|
||
| default: | ||
| throw new JsonException(RMResources.SpatialFailedToDeserializeCrs); | ||
| } | ||
|
|
||
| } | ||
| /// <summary> | ||
| /// Serializes a CRS to JSON. | ||
| /// Outputs different JSON structures based on CRS type (Named, Linked, or Unspecified). | ||
| /// </summary> | ||
| public override void Write(Utf8JsonWriter writer, Crs crs, JsonSerializerOptions options) | ||
| { | ||
| if (crs == null) | ||
| { | ||
| writer.WriteNullValue(); | ||
| return; | ||
| } | ||
|
|
||
| switch (crs.Type) | ||
| { | ||
| case CrsType.Linked: | ||
| { | ||
| writer.WriteStartObject(); | ||
| LinkedCrs linkedCrs = (LinkedCrs)crs; | ||
| writer.WriteString(STJMetaDataFields.Type, "link"); | ||
| writer.WritePropertyName(STJMetaDataFields.Properties); | ||
| writer.WriteStartObject(); | ||
| writer.WriteString(STJMetaDataFields.Href, linkedCrs.Href); | ||
| if (linkedCrs.HrefType != null) | ||
| { | ||
| writer.WriteString(STJMetaDataFields.Type, linkedCrs.HrefType); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| writer.WriteEndObject(); | ||
| break; | ||
| } | ||
| case CrsType.Named: | ||
| { | ||
| writer.WriteStartObject(); | ||
| NamedCrs namedCrs = (NamedCrs)crs; | ||
| writer.WriteString(STJMetaDataFields.Type, "name"); | ||
| writer.WritePropertyName(STJMetaDataFields.Properties); | ||
| writer.WriteStartObject(); | ||
| writer.WriteString(STJMetaDataFields.Name, namedCrs.Name); | ||
| writer.WriteEndObject(); | ||
| writer.WriteEndObject(); | ||
| break; | ||
| } | ||
| case CrsType.Unspecified: | ||
| writer.WriteNullValue(); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.