Skip to content

Consider migrating from Newtonsoft.Json to System.Text.Json to enable AOT publishing #225

Description

@petrsnd

Summary

The SafeguardDotNet SDK currently uses Newtonsoft.Json for all serialization. This blocks downstream consumers from using .NET Native AOT publishing, because Newtonsoft.Json relies heavily on runtime reflection that AOT cannot support.

Benefits of AOT for Downstream Consumers

  • ~60% smaller single-file binaries (~15MB vs ~70MB)
  • Near-instant startup (~50ms vs ~1-2s)
  • No .NET runtime bundled in the output
  • Lower memory footprint (~30-50% reduction)
  • Predictable performance with no JIT compilation pauses

Proposed Approach

Migrate to System.Text.Json with source generators (JsonSerializerContext). This would:

  1. Enable full AOT compatibility (no reflection-based serialization)
  2. Improve serialization performance even without AOT (source generators are faster)
  3. Remove the Newtonsoft.Json transitive dependency for consumers

This is a breaking change for anyone using JObject/JToken directly from the SDK's public API surface, so it would likely target a major version bump.

Alternatives

  • Keep Newtonsoft.Json, accept larger binaries (current state)
  • Dual-target with an abstraction layer (complex, not recommended)
  • Use System.Text.Json only for internal serialization while keeping Newtonsoft for public API (leaky)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions