[{"data":1,"prerenderedAt":106},["ShallowReactive",2],{"/2025/11/18-jsonserializeroptions-numberhandling-allowreadingfromstring-and-strict":3},{"id":4,"title":5,"body":6,"date":97,"description":47,"extension":98,"meta":99,"navigation":100,"path":101,"robots":102,"seo":103,"stem":104,"__hash__":105},"posts/2025/11/18 JsonSerializerOptions-NumberHandling-AllowReadingFromString-and-Strict.md","18 JsonSerializerOptions NumberHandling AllowReadingFromString And Strict",{"type":7,"value":8,"toc":94},"minimark",[9,18,21,34,48,51,59,73,75,86],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"jsonserializeroptions-numberhandling-allowreadingfromstring-and-strict","JsonSerializerOptions NumberHandling AllowReadingFromString and Strict",[19,20],"br",{},[22,23,24,25,29,30,33],"p",{},"After all the attempts to fix OpenAPI document, I noticed that Orval intepreted one of the property as ",[26,27,28],"strong",{},"unknown"," type which is supposed to be integer, thus ",[26,31,32],{},"number"," type. I checked the OpenAPI document and it has the following type and format:",[35,36,37],"code-block",{},[38,39,44],"pre",{"className":40,"code":42,"language":43},[41],"language-text","type: \"^-?(?:0|[1-9]\\d*)$\",\nformat: \"int32\"\n","text",[45,46,42],"code",{"__ignoreMap":47},"",[22,49,50],{},"For Orval to intepret it properly as number, I need it to be:",[35,52,53],{},[38,54,57],{"className":55,"code":56,"language":43},[41],"type: \"integer\",\nformat: \"int32\"\n",[45,58,56],{"__ignoreMap":47},[22,60,61,62],{},"So, I check the backend and found out that it is due to JsonSerializeOptions.NumberHandling is set to AllowReadingFromString by default. ",[63,64,67],"span",{"className":65},[66],"text-blue-600",[68,69,70],"a",{"href":70,"rel":71},"https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/configure-options#web-defaults-for-jsonserializeroptions",[72],"nofollow",[19,74],{},[22,76,77,78,85],{},"I want to set NumberHandling to Strict globally. Since I use minimal api, this article helps ",[63,79,81],{"className":80},[66],[68,82,83],{"href":83,"rel":84},"https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/responses?view=aspnetcore-10.0#configure-json-serialization-options-globally",[72],". I just need to add the following on my backend code:",[35,87,88],{},[38,89,92],{"className":90,"code":91,"language":43},[41],"builder.Services.ConfigureHttpJsonOptions(options =>\n{\n    options.SerializerOptions.TypeInfoResolverChain.Insert(0, HttpApiJsonSerializerContext.Default);\n});\n",[45,93,91],{"__ignoreMap":47},{"title":47,"searchDepth":95,"depth":95,"links":96},2,[],"2025-11-18T00:00:00.000Z","md",{},true,"/2025/11/18-jsonserializeroptions-numberhandling-allowreadingfromstring-and-strict",null,{"title":5,"description":47},"2025/11/18 JsonSerializerOptions-NumberHandling-AllowReadingFromString-and-Strict","NV9tkWoJzIWN3PkXOlZg3zGqduzDB-NdfElIaeCuS60",1785167452499]