Skip to content

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

Merged
MatejMa2ur merged 1 commit intorelease/0.xfrom
main
Nov 24, 2025
Merged

Fix #157: GeoJsonDataConverter is not applied correctly when s... (#158)#159
MatejMa2ur merged 1 commit intorelease/0.xfrom
main

Conversation

@MatejMa2ur
Copy link
Member

  • 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.

* 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>
@MatejMa2ur MatejMa2ur merged commit d234f4c into release/0.x Nov 24, 2025
8 checks passed
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.

1 participant