AspNetCoreOData
AspNetCoreOData copied to clipboard
Change PageResult<T> property names on serialization
Hi,
I have a .NET 5 web API with OData 8.0.6 installed. Currently I'm hitting an endpoint and I get the result as:
{
"items": [ ... ],
"count": 10
}
I want the the JSON response to be Uppercased like "Items" and "Count". I see there is an extension method EnableLowerCamelCase but I don't see any other method witch does the opposite like pascal casing.
ConfigureServices goes like:
services.AddControllers(options =>
{
options.Filters.Add(typeof(MyCustomFilter));
})
.AddJsonOptions(options =>
{
// I also applied pascal casing for API
options.JsonSerializerOptions.PropertyNamingPolicy = null;
})
.AddOData(opt =>
{
var builder = new ODataConventionModelBuilder();
// this is the data source for PagingResult I'm returning
builder.Function("Myfunction").ReturnsCollection<MyfunctionResult>();
opt.AddRouteComponents(builder.GetEdmModel());
});
How can I achieve a paging result response to look like this?
{
"Items": [ ... ],
"Count": 10
}
Looks like the values for these properties are completely hardcoded: https://github.com/OData/AspNetCoreOData/blob/69eec03c7003fe12d92cdc619efdc16781683694/src/Microsoft.AspNetCore.OData/Results/PageResultValueConverter.cs#L60-L71
@julealgon Thanks, much appreciated! Anyway do you think its a good idea to request change to support pascal casing for paging result?
Anyway do you think its a good idea to request change to support pascal casing for paging result?
I definitely do, hence my upvote on your post. This should definitely be configurable in a way, if not only for consistency purposes.
@julealgon How does it work though? This is the first issue I've ever created. Not sure how to proceed
@julealgon How does it work though? This is the first issue I've ever created. Not sure how to proceed
Having this issue open here should be enough. People on the team will eventually look into it.
Any progress with this issue? Is there a plan to fix it in the near future? Its a pinpoint - If the entire API is PascalCase, it looks ugly that only the page result contains camelCase properties.