Skip to content

Remove Newtonsoft.Json dependency and enhance FieldValueHelper enum resolution#274

Merged
niemyjski merged 6 commits into
mainfrom
remove-newtonsoft-json-dependency
May 15, 2026
Merged

Remove Newtonsoft.Json dependency and enhance FieldValueHelper enum resolution#274
niemyjski merged 6 commits into
mainfrom
remove-newtonsoft-json-dependency

Conversation

@niemyjski
Copy link
Copy Markdown
Member

Summary

  • Remove transitive Newtonsoft.Json dependency: Delete the \Foundatio.JsonNet\ PackageReference/ProjectReference from \Foundatio.Repositories.csproj\ and remove the Newtonsoft custom converters (\AggregationsNewtonsoftJsonConverter, \BucketsNewtonsoftJsonConverter) that are no longer needed since the API surface is fully System.Text.Json.
  • Remove Newtonsoft attributes from models: Strip all [Newtonsoft.Json.*]\ attributes from \IAggregate, \IBucket, \FindResults, \FindHit, and \CountResult\ — STJ equivalents ([JsonConstructor], [JsonInclude], [JsonConverter]) are already in place.
  • Enhance FieldValueHelper enum resolution: Add [EnumMember(Value)]\ attribute fallback after [JsonStringEnumMemberName]\ in \GetEnumStringValue, fixing silent Elasticsearch query bugs when custom enum serialization names are used.
  • Update test infrastructure: Remove \JsonNetSerializer\ from \SerializerTestHelper.GetTextSerializers()\ so all tests validate the STJ-only path. Add comprehensive \FieldValueHelperTests\ covering enum attribute resolution and primitive type conversions.

Test plan

  • Solution builds with 0 errors and 0 warnings
  • All 122 core repository tests pass (STJ-only serialization)
  • Elasticsearch integration tests pass (requires running ES instance via \docker compose up)
  • Verify no downstream consumers rely on the removed Newtonsoft converters

…esolution

Remove the transitive Newtonsoft.Json dependency that was unnecessarily pulled in via Foundatio.JsonNet, completing the System.Text.Json migration:

- Delete AggregationsNewtonsoftJsonConverter and BucketsNewtonsoftJsonConverter
- Remove all [Newtonsoft.Json.*] attributes from IAggregate, IBucket, FindResults, FindHit, and CountResult models (STJ equivalents already in place)
- Remove Foundatio.JsonNet PackageReference/ProjectReference from csproj
- Update SerializerTestHelper to STJ-only

Additionally, enhance FieldValueHelper.GetEnumStringValue to resolve enum values using [EnumMember(Value)] as a fallback after [JsonStringEnumMemberName], fixing silent Elasticsearch query bugs when custom enum serialization names are used.

Add comprehensive FieldValueHelper unit tests covering enum attribute resolution and all primitive type conversions.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the library’s Json.NET (Newtonsoft.Json) integration to standardize on System.Text.Json across the public API surface, and improves Elasticsearch query value handling by resolving enum string values from serialization-related attributes.

Changes:

  • Removed the Foundatio.JsonNet reference and deleted the Json.NET aggregation/bucket converters.
  • Removed Newtonsoft.Json attributes from aggregation and result models, leaving System.Text.Json attributes/converters in place.
  • Enhanced FieldValueHelper.ToFieldValue to resolve enum values via [JsonStringEnumMemberName] and [EnumMember(Value=...)], and added tests for enum + primitive conversions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Foundatio.Repositories.Tests/Serialization/SerializerTestHelper.cs Removes Json.NET serializer from the serializer matrix so tests validate STJ-only.
tests/Foundatio.Repositories.Elasticsearch.Tests/FieldValueHelperTests.cs Adds test coverage for enum attribute resolution and primitive conversions to FieldValue.
src/Foundatio.Repositories/Serialization/BucketsNewtonsoftJsonConverter.cs Deletes Json.NET bucket converter implementation.
src/Foundatio.Repositories/Serialization/AggregationsNewtonsoftJsonConverter.cs Deletes Json.NET aggregation converter implementation.
src/Foundatio.Repositories/Models/FindResults.cs Removes Newtonsoft.Json constructor/property attributes from result models.
src/Foundatio.Repositories/Models/Aggregations/IBucket.cs Removes Newtonsoft.Json converter attribute from IBucket (STJ converter remains).
src/Foundatio.Repositories/Models/Aggregations/IAggregate.cs Removes Newtonsoft.Json converter attribute from IAggregate (STJ converter remains).
src/Foundatio.Repositories/Foundatio.Repositories.csproj Drops Foundatio.JsonNet dependency.
src/Foundatio.Repositories.Elasticsearch/Utility/FieldValueHelper.cs Adds enum handling with attribute-based string resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Foundatio.Repositories/Foundatio.Repositories.csproj
Comment thread src/Foundatio.Repositories.Elasticsearch/Utility/FieldValueHelper.cs Outdated
niemyjski added 4 commits May 14, 2026 14:24
- Replace all JsonConvert usage in ES tests with System.Text.Json.JsonSerializer

- Add ConcurrentDictionary cache for enum string resolution in FieldValueHelper

- Use GetField instead of GetMember for more efficient reflection
Caches attribute resolution per enum Type (not per value), so growth is bounded by the number of distinct enum types in the app. Flags combinations and undefined values fall through to ToString() without polluting the cache.
@niemyjski niemyjski self-assigned this May 15, 2026
Comment thread src/Foundatio.Repositories/Foundatio.Repositories.csproj Outdated
@niemyjski niemyjski merged commit 1e337ae into main May 15, 2026
6 checks passed
@niemyjski niemyjski deleted the remove-newtonsoft-json-dependency branch May 15, 2026 11:33
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