Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonConverters not working properly on OData response #1186

Open
sivak4Net opened this issue Mar 4, 2024 · 2 comments
Open

JsonConverters not working properly on OData response #1186

sivak4Net opened this issue Mar 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@sivak4Net
Copy link

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 sivak4Net added the bug Something isn't working label Mar 4, 2024
@sivak4Net
Copy link
Author

sivak4Net commented Mar 4, 2024

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 Get(string dataSourceName, ODataQueryOptions options)
{

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



return Ok(dataSource);

}

private IQueryable ApplyODataQuery(string dataSourceName, ODataQueryOptions options)
{
IQueryable 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 with out converter i am able to get the data as expected but if i register that converter then it's not working

@julealgon
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants