Skip to content

Add IsoDateTimeConverter and StringEnumConverter#109

Merged
twogood merged 5 commits intomainfrom
DefaultJsonConverters
Oct 20, 2025
Merged

Add IsoDateTimeConverter and StringEnumConverter#109
twogood merged 5 commits intomainfrom
DefaultJsonConverters

Conversation

@twogood
Copy link
Owner

@twogood twogood commented Oct 20, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved JSON serialization: consistent date-time formatting, string-enum handling, and refined camelCase property naming.
    • Responses now omit null values to reduce payload size and streamline client processing.
  • Tests

    • Updated request payloads in tests to always include a ReviewId field for more reliable validation.

@twogood twogood self-assigned this Oct 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2025

Walkthrough

Updated Newtonsoft.Json defaults: added IsoDateTimeConverter and StringEnumConverter, changed CamelCaseNamingStrategy constructor arguments, and set serializer settings to ignore null values; a unit test JSON payload injection was adjusted and two unused usings were removed.

Changes

Cohort / File(s) Change Summary
JSON Serialization Configuration
Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs
- DefaultJsonConverters now contains IsoDateTimeConverter and SimpleValueObjectConverter.
- CamelCasePropertyNamesContractResolver.NamingStrategy uses CamelCaseNamingStrategy(false, false).
- DefaultJsonSerializerSettings.Converters now prepends new StringEnumConverter() to the default converters and sets NullValueHandling = NullValueHandling.Ignore.
- CamelCaseSerializerSettings.Converters now includes new StringEnumConverter(CamelCasePropertyNamesContractResolver.NamingStrategy!) plus the default converters and sets NullValueHandling = NullValueHandling.Ignore.
Unit Test JSON payload
Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs
- TestPostJsonAsync JSON modification changed: instead of replacing a null ReviewId token, the test now injects a ReviewId field at the start of the JSON object (replace first "{" with {"ReviewId":"*REVIEW_ID*", ...}).
Using cleanup
Activout.RestClient.Newtonsoft.Json/RestClientBuilderNewtonsoftJsonExtensions.cs
- Removed unused using directives: System.Collections.Immutable and System.Diagnostics.CodeAnalysis. No behavioral changes.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Client code
  participant RestClient as RestClient
  participant JsonNet as Newtonsoft.Json

  rect rgba(200,230,255,0.4)
  Caller->>RestClient: Post object (e.g., request DTO)
  RestClient->>JsonNet: Serialize(object, settings)
  note right of JsonNet #eef7ff: Settings include\n- StringEnumConverter\n- IsoDateTimeConverter\n- SimpleValueObjectConverter\n- CamelCaseNamingStrategy(false,false)\n- NullValueHandling.Ignore
  JsonNet-->>RestClient: JSON payload
  RestClient->>Caller: send HTTP request with JSON
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through settings, nibbling care,
Dates and enums now handled there.
Camel names tweaked with gentle shove,
Nulls skip past — a quieter shove,
Tiny rabbit, tidy code and flair. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add IsoDateTimeConverter and StringEnumConverter" is fully related to the main change in the changeset. The title accurately summarizes the primary modifications to NewtonsoftJsonDefaults.cs, which add IsoDateTimeConverter to DefaultJsonConverters and StringEnumConverter to both DefaultJsonSerializerSettings and CamelCaseSerializerSettings. The title is concise, clear, and specific enough that a reviewer can understand the key purpose of the change. While the PR includes supporting changes such as setting NullValueHandling to Ignore and adjusting NamingStrategy parameters, these are secondary modifications that enable the primary feature of adding the converters.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DefaultJsonConverters

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1913dfe and 573a64e.

📒 Files selected for processing (1)
  • Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.cs: Use [] list syntax for collections
Use file-scoped namespaces
Use primary constructors wherever possible
Use records for data transfer objects (DTOs) and immutable data structures
Use var for local variable declarations when possible
Use expression-bodied members for simple methods and properties
Use pattern matching for type checks and deconstruction
Use using statements for resource management
Use async and await for asynchronous programming
Never include "Async" in method names
Only include comments that explain why something is done, not what is done

Files:

  • Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs
🧬 Code graph analysis (1)
Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (1)
Activout.RestClient.Json/SimpleValueObjectConverter.cs (1)
  • JsonConverter (40-50)
🔇 Additional comments (4)
Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (4)

3-3: LGTM! Necessary import for the new converters.


25-25: LGTM! More explicit and conservative naming strategy.

The explicit parameters (false, false) make the behavior clearer and prevent unintended dictionary key transformations and JsonProperty attribute overrides.


37-37: Verify this potentially breaking change.

Adding NullValueHandling.Ignore changes serialization behavior by omitting null values from the JSON output. This is common practice but could break consumers that explicitly check for null properties versus missing properties.

Ensure this change is:

  1. Documented in release notes as a breaking change
  2. Tested with existing API consumers
  3. Intentional for this settings object

28-31: Clarify the intentional difference in NullValueHandling.

DefaultJsonSerializerSettings does not have NullValueHandling.Ignore, while CamelCaseSerializerSettings does (line 37). This creates inconsistent serialization behavior between the two settings objects.

Is this intentional? If so, the distinction should be documented. If not, consider adding it here as well:

 public static readonly JsonSerializerSettings DefaultJsonSerializerSettings = new()
 {
-    Converters = DefaultJsonConverters.ToList()
+    Converters = DefaultJsonConverters.ToList(),
+    NullValueHandling = NullValueHandling.Ignore
 };

Note: The AI summary mentions adding NullValueHandling.Ignore to DefaultJsonSerializerSettings, but this change is not present in the code.

@twogood twogood changed the title Add IsoDateTimeConverter and SimpleValueObjectConverter Add IsoDateTimeConverter and StringEnumConverter Oct 20, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs (1)

200-200: Consider a more robust JSON manipulation approach.

The string replacement of the first { character adapts correctly to the new NullValueHandling.Ignore behavior but is fragile—it assumes the JSON structure and would break if the request contains nested objects or arrays. Consider parsing, modifying, and re-serializing the JSON instead:

-                    content = content.Replace("{", "{\"ReviewId\":\"*REVIEW_ID*\", ");
+                    var json = JsonConvert.DeserializeObject<dynamic>(content);
+                    json.ReviewId = "*REVIEW_ID*";
+                    content = JsonConvert.SerializeObject(json);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73e5bf5 and e3d27c4.

📒 Files selected for processing (3)
  • Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs (1 hunks)
  • Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (2 hunks)
  • Activout.RestClient.Newtonsoft.Json/RestClientBuilderNewtonsoftJsonExtensions.cs (0 hunks)
💤 Files with no reviewable changes (1)
  • Activout.RestClient.Newtonsoft.Json/RestClientBuilderNewtonsoftJsonExtensions.cs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.cs: Use [] list syntax for collections
Use file-scoped namespaces
Use primary constructors wherever possible
Use records for data transfer objects (DTOs) and immutable data structures
Use var for local variable declarations when possible
Use expression-bodied members for simple methods and properties
Use pattern matching for type checks and deconstruction
Use using statements for resource management
Use async and await for asynchronous programming
Never include "Async" in method names
Only include comments that explain why something is done, not what is done

Files:

  • Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs
  • Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs
🧬 Code graph analysis (1)
Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (1)
Activout.RestClient.Json/SimpleValueObjectConverter.cs (1)
  • JsonConverter (40-50)
🔇 Additional comments (5)
Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs (5)

3-3: LGTM!

The import is necessary for IsoDateTimeConverter and StringEnumConverter.


24-24: LGTM!

Making the CamelCaseNamingStrategy parameters explicit (processDictionaryKeys: false, overrideSpecifiedNames: false) improves clarity without changing behavior.


35-41: LGTM! Past review comment addressed.

The StringEnumConverter now correctly uses CamelCasePropertyNamesContractResolver.NamingStrategy, ensuring enum values are serialized in camelCase to match property naming. This addresses the previous review concern. The use of spread syntax (..DefaultJsonConverters) follows the coding guidelines for collection syntax.

Note: NullValueHandling.Ignore is a breaking change (see comment on lines 29-30).

Based on past review comment.


29-30: The NullValueHandling.Ignore default is confirmed intentional—no external breaking impact found.

Git history (commit 0b17940) explicitly shows this as a deliberate design decision. The test suite comprehensively validates both Include and Ignore behaviors across both JSON implementations with conditional handling at line 263–265, indicating maintainers are aware of the behavioral difference.

No CHANGELOG, deprecation warnings, or migration guidance exists in the repository. The codebase shows no documented external API consumers or version-controlled breaking change protocols. While the change is technically a semantic shift in null serialization, evidence within the repository suggests this is an intentional API evolution rather than an oversight.

If external consumers exist outside this repository, they would require migration guidance for null value expectations—verify whether such consumers are documented elsewhere.


16-20: Both concerns verified as non-issues; code change is correct.

The SimpleValueObjectConverter is the correct Newtonsoft.Json-compatible version from the Activout.RestClient.Newtonsoft.Json namespace (confirmed by file path and JsonConverter base class inheritance).

The IsoDateTimeConverter addition is not a breaking change. The existing test TestQueryParamAsync already expects DateTime values to be serialized in ISO 8601 format (2017-01-01T00:00:00.0000000Z), which is exactly what IsoDateTimeConverter produces. This indicates the change aligns with the library's intended behavior.

@twogood twogood merged commit 49e471b into main Oct 20, 2025
9 checks passed
@twogood twogood deleted the DefaultJsonConverters branch October 20, 2025 18:58
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