Fix #157: GeoJsonDataConverter is not applied correctly when s... (#158)#159
Merged
MatejMa2ur merged 1 commit intorelease/0.xfrom Nov 24, 2025
Merged
Fix #157: GeoJsonDataConverter is not applied correctly when s... (#158)#159MatejMa2ur merged 1 commit intorelease/0.xfrom
MatejMa2ur merged 1 commit intorelease/0.xfrom
Conversation
* fix: apply GeoJsonDataConverter when calling SetSourceData The SetSourceData method was failing with serialization errors because the GeoJsonDataConverter was not being applied when passing source.Data directly to JS interop. The converter attribute is on the property in GeoJsonSource, so it was only applied when serializing the entire object. This fix: - Serializes the entire GeoJsonSource to ensure the converter is applied - Extracts just the "data" field from the serialized JSON - Passes the properly serialized data to JavaScript Also added support for setSourceData in bulk transactions and comprehensive tests to verify the fix works for both FeatureCollection and URL string data. Fixes #157 * test: add comprehensive tests for SetSourceData fix Added two new test suites to ensure the SetSourceData fix works correctly: 1. SetSourceDataTests.cs: - Tests GeoJsonSource serialization with FeatureCollection - Tests single Feature serialization - Tests URL string data - Tests complex properties and geometry types - Tests data extraction doesn't include source configuration - Tests JsonElement.Clone() for bulk transactions - Tests edge cases like empty collections and null properties - Performance tests for large datasets 2. BulkTransactionTests.cs: - Tests setSourceData support in bulk transactions - Tests multiple setSourceData operations in one transaction - Tests mixing setSourceData with other operations - Tests complex GeoJSON preservation in transactions - Tests URL strings in bulk transactions - Tests operation ordering - Performance tests for bulk operations These tests verify that the GeoJsonDataConverter is properly applied and that the extracted data maintains the correct GeoJSON structure without including source configuration properties. * refactor: simplify SetSourceData using JsonNode instead of JsonDocument Improved the SetSourceData implementation to be simpler and more efficient: BEFORE (JsonDocument approach - 4 lines): - Serialize to string - Parse string to JsonDocument - Extract property with Clone() - Requires 'using' statement AFTER (JsonNode approach - 2 lines): - Serialize directly to JsonNode - Extract property with indexer - No Clone() needed - No 'using' statement Benefits: ✅ Simpler code (4 lines → 2 lines) ✅ More efficient (no string allocation/parsing) ✅ More intuitive syntax (["data"] vs GetProperty) ✅ No manual disposal needed ✅ Same functionality and test coverage Also added: - Comprehensive documentation explaining the fix and why it works - SerializationApproachTests comparing both approaches - Updated all tests to use the simpler JsonNode pattern The fix still works the same way: serialize the full GeoJsonSource to ensure the converter is applied, then extract just the "data" field. * docs: add visual explanation of SetSourceData fix * fix(interop): ensure correct serialization of GeoJsonSource data - Refactored `SetSourceData` to use `JsonSerializer.SerializeToNode` for extracting the correctly-converted `data` field, replacing the less efficient `JsonDocument` approach. - Simplifies code, improves performance, and ensures compatibility with JS interop by providing properly serialized GeoJSON data without additional source configuration. * chore(release): bump version to 1.4.0-pre2 - Updated the project version in `Community.Blazor.MapLibre.csproj` from 1.4.0-pre1 to 1.4.0-pre2. This version bump reflects preparation for a new pre-release, ensuring alignment with semantic versioning and readiness for further development or testing. --------- Co-authored-by: Claude <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The SetSourceData method was failing with serialization errors because the GeoJsonDataConverter was not being applied when passing source.Data directly to JS interop. The converter attribute is on the property in GeoJsonSource, so it was only applied when serializing the entire object.
This fix:
Also added support for setSourceData in bulk transactions and comprehensive tests to verify the fix works for both FeatureCollection and URL string data.
Fixes #157
Added two new test suites to ensure the SetSourceData fix works correctly:
SetSourceDataTests.cs:
BulkTransactionTests.cs:
These tests verify that the GeoJsonDataConverter is properly applied and that the extracted data maintains the correct GeoJSON structure without including source configuration properties.
Improved the SetSourceData implementation to be simpler and more efficient:
BEFORE (JsonDocument approach - 4 lines):
AFTER (JsonNode approach - 2 lines):
Benefits:
✅ Simpler code (4 lines → 2 lines)
✅ More efficient (no string allocation/parsing)
✅ More intuitive syntax (["data"] vs GetProperty)
✅ No manual disposal needed
✅ Same functionality and test coverage
Also added:
The fix still works the same way: serialize the full GeoJsonSource to ensure the converter is applied, then extract just the "data" field.
docs: add visual explanation of SetSourceData fix
fix(interop): ensure correct serialization of GeoJsonSource data
SetSourceDatato useJsonSerializer.SerializeToNodefor extracting the correctly-converteddatafield, replacing the less efficientJsonDocumentapproach.Community.Blazor.MapLibre.csprojfrom 1.4.0-pre1 to 1.4.0-pre2. This version bump reflects preparation for a new pre-release, ensuring alignment with semantic versioning and readiness for further development or testing.