AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

JsonConverters not working properly on OData response

Open sivak4Net opened this issue 1 year ago • 2 comments

Assemblies affected Which assemblies and versions are known to be affected e.g. ASP.NET Core OData 8.x

Describe the bug A clear and concise description of what the bug is.

Reproduce steps The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

Data Model Please share your Data model, for example, your C# class.

EDM (CSDL) Model Please share your Edm model, for example, CSDL file. You can send $metadata to get a CSDL XML content.

Request/Response Please share your request Uri, head or the request body Please share your response head, body.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Please share your call stack or any error message Add any other context about the problem here.

sivak4Net avatar Mar 04 '24 13:03 sivak4Net

I am using AspNetCore.OData 8.2.5 and .net6 Api Have a dbcontext entity as Product, On top of Product i have a json converter which is not working as expected like From Product entity response i want to concate the properties

`[JsonConverter(typeof(ProductDataConverter))] public class Product { public int Id { get; set; } public string Name { get; set; }

public List<DataRow> Data { get; set; }
public string Schema { get; set; }

}

public class DataRow { public int Id { get; set; } public int ProductId { get; set; } public string Data { get; set; } }`

my api will be `public async Task<IActionResult> Get(string dataSourceName, ODataQueryOptions<Product> options) {

//var dataSource = await _productDataService.GetDataProductByQuery(dataSourceName).FirstAsync();
var dataSource = await ApplyODataQuery(dataSourceName, options).FirstOrDefaultAsync();         



return Ok(dataSource);

}

private IQueryable ApplyODataQuery(string dataSourceName, ODataQueryOptions<Product> options) { IQueryable<Product> dataSource = _productDataService.GetDataSourceByQuery(dataSourceName).IgnoreAutoIncludes(); var result = options.ApplyTo(dataSource); return result.Cast();
}`

When i execute this code then i am getting the below exception "Error": { "Code": 500, "Message": "Token PropertyName in state Property would result in an invalid JSON object. Path 'Container.Value[0].Instance'." }

Any help would be appreciate, i tried many ways but nothing is working out, Once we execute the db query if i see the result it showing as AspNetCore.SelectAllExpand<Product> with out converter i am able to get the data as expected but if i register that converter then it's not working

sivak4Net avatar Mar 04 '24 13:03 sivak4Net

On top of Product i have a json converter which is not working as expected like From Product entity response i want to concate the properties

Can you elaborate a bit more on this? What does your converter to, and why do you need a converter in the first place?

julealgon avatar Mar 04 '24 14:03 julealgon