You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Repo Assist] Add OmitNullFields static parameter to JsonProvider (closes#1245) (#1638)
* Add OmitNullFields static parameter to JsonProvider
When OmitNullFields=true, optional fields with value None are omitted
from the generated JSON rather than serialized as null.
This addresses the request in issue #1245: users integrating with strict
APIs that reject null fields can now use:
type ColorProvider = JsonProvider<"...", SampleIsList=true, OmitNullFields=true>
let value = ColorProvider.Root(color = "Blue", code = None)
// Serializes as: {"color": "Blue"} (no "code": null)
Changes:
- JsonRuntime.fs: Add CreateRecordOmitNulls() that filters null fields
- JsonGenerator.fs: Add OmitNullFields field to JsonGenerationContext;
use CreateRecordOmitNulls when OmitNullFields=true
- JsonProvider.fs: Add OmitNullFields static parameter (default false)
- TypeProviderInstantiation.fs: Update test helper with new param
- JsonProvider.fs (tests): Add 3 tests covering new behavior
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* ci: trigger CI checks
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
"""<summary>Typed representation of a JSON document.</summary>
@@ -192,7 +195,8 @@ type public JsonProvider(cfg: TypeProviderConfig) as this =
192
195
</param>
193
196
<param name='Schema'>Location of a JSON Schema file or a string containing a JSON Schema document. When specified, Sample and SampleIsList must not be used.</param>
194
197
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings (e.g. "2023-01-15") are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>
195
-
<param name='UseOriginalNames'>When true, JSON property names are used as-is for generated property names instead of being normalized to PascalCase. Defaults to false.</param>"""
198
+
<param name='UseOriginalNames'>When true, JSON property names are used as-is for generated property names instead of being normalized to PascalCase. Defaults to false.</param>
199
+
<param name='OmitNullFields'>When true, optional fields with value None are omitted from the generated JSON rather than serialized as null. Defaults to false.</param>"""
196
200
197
201
do jsonProvTy.AddXmlDoc helpText
198
202
do jsonProvTy.DefineStaticParameters(parameters, buildTypes)
0 commit comments