Skip to content

[Code Quality] ServiceExporter.ExportJson and JsonServiceSerializer.Serialize use different JsonSerializerSettings — asymmetric JSON output #1000

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info / Code Quality

Files:

  • src/Servy.Core/Services/ServiceExporter.cs lines 69-76 and 84-102
  • src/Servy.Core/Services/JsonServiceSerializer.cs lines 44-60

Finding

The codebase has two parallel JSON-export paths for the same ServiceDto, and they configure Newtonsoft.Json differently, so the output for the same DTO is not byte-for-byte identical.

ServiceExporter.ExportJson(ServiceDto service):

return JsonConvert.SerializeObject(service, Newtonsoft.Json.Formatting.Indented,
    new JsonSerializerSettings
    {
        NullValueHandling = NullValueHandling.Ignore
    });

JsonServiceSerializer.Serialize(ServiceDto? dto):

return JsonConvert.SerializeObject(dto, Formatting.Indented, JsonSecurity.UntrustedDataSettings);

JsonSecurity.UntrustedDataSettings (src/Servy.Core/Security/JsonSecurity.cs):

public static readonly JsonSerializerSettings UntrustedDataSettings = new JsonSerializerSettings
{
    TypeNameHandling = TypeNameHandling.None,
    MaxDepth = 32,
    MetadataPropertyHandling = MetadataPropertyHandling.Ignore
};

The two settings objects do not overlap:

  • ServiceExporter omits null-valued properties (NullValueHandling.Ignore) — produces a smaller JSON file with only set fields.
  • JsonServiceSerializer emits all null-valued properties — produces a larger JSON file with explicit null everywhere.

Both paths are reachable from ServiceCommands (Servy and Servy.Manager) and from the CLI, so the same export operation can produce different files depending on which code path is used.

Why this matters

Suggested fix

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions