Skip to content

Fix #157: GeoJsonDataConverter is not applied correctly when s...#158

Merged
MatejMa2ur merged 6 commits intomainfrom
claude/lookup-reference-01UUbGk9mLnPhCP8H6E14rTv
Nov 24, 2025
Merged

Fix #157: GeoJsonDataConverter is not applied correctly when s...#158
MatejMa2ur merged 6 commits intomainfrom
claude/lookup-reference-01UUbGk9mLnPhCP8H6E14rTv

Conversation

@MatejMa2ur
Copy link
Member

erializing using SetSourceData

claude and others added 6 commits November 24, 2025 16:38
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
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.
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.
- 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.
- 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.
@MatejMa2ur MatejMa2ur merged commit 7234eac into main Nov 24, 2025
9 checks passed
MatejMa2ur added a commit that referenced this pull request Nov 24, 2025
Fix #157: GeoJsonDataConverter is not applied correctly when s... (#158)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants