Skip to content

Commit 697b1b6

Browse files
committed
Fixed custom JSON serialization options not taking effect
1 parent 9eec845 commit 697b1b6

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

InertiaNetCore/Models/InertiaOptions.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ public class InertiaOptions
1919

2020
public object JsonSerializerOptions { get; set; } = DefaultJsonSerializerOptions;
2121

22-
public Func<object, string> JsonSerializeFn { get; set; } = model => JsonSerializer.Serialize(model, DefaultJsonSerializerOptions);
22+
public Func<object, InertiaOptions, string> JsonSerializeFn { get; set; } = (model, o) =>
23+
{
24+
return JsonSerializer.Serialize(model, o.JsonSerializerOptions as JsonSerializerOptions);
25+
};
2326
}

InertiaNetCore/ResponseFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task<IHtmlContent> Html(dynamic model)
5454
}
5555
}
5656

57-
var data = options.Value.JsonSerializeFn(model);
57+
var data = options.Value.JsonSerializeFn(model, options.Value);
5858
var encoded = WebUtility.HtmlEncode(data);
5959

6060
return new HtmlString($"<div id=\"app\" data-page=\"{encoded}\"></div>");

InertiaNetCore/Ssr/SsrGateway.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class SsrGateway(IHttpClientFactory httpClientFactory, IOptions<Inertia
99
{
1010
public async Task<SsrResponse?> Dispatch(dynamic model, string url)
1111
{
12-
var json = options.Value.JsonSerializeFn(model);
12+
var json = options.Value.JsonSerializeFn(model, options.Value);
1313

1414
var content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
1515

0 commit comments

Comments
 (0)