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

OData enum values use string values #221

Closed
CupcakeThief opened this issue Oct 25, 2020 · 6 comments · Fixed by #226
Closed

OData enum values use string values #221

CupcakeThief opened this issue Oct 25, 2020 · 6 comments · Fixed by #226

Comments

@CupcakeThief
Copy link
Contributor

OData/WebApi#1785

The default conversion for enums in OData is to use the string values...

Need to add
new JsonStringEnumConverter(null)
to AddOdataSupport converters.

@gustavnavar
Copy link
Owner

Version 2.0.0 solves this issue

@CupcakeThief
Copy link
Contributor Author

Hmm I am still getting the same type conversion error, did this fix deffo make it into 2.0.0?

@gustavnavar
Copy link
Owner

Yes

can you send me the error that you get?

@CupcakeThief
Copy link
Contributor Author

The JSON value could not be converted to Blackbot.Model.Prospects.ProspectStatus. Path: $.value[0].Status | LineNumber: 0 | BytePositionInLine: 324.

{"@odata.context":"https://localhost:5001/odata/$metadata#Prospects","@odata.count":5765,"value":[{"Id":"2019092517303934_30_min_EUR-GBP","ChartName":"m30","Symbol":"EUR/GBP","MotherStartDateTime":"2019-09-25T17:30:00+01:00","MotherHigh":0.000000,"MotherLow":0.000000,"ChildEndDateTime":"0001-01-01T00:00:00Z","Status":"Won"

I'll have a bit more of a poke about this evening

@CupcakeThief
Copy link
Contributor Author

Have simplified my test page.

shared:

    public enum MyEnum
    {
        Foo,
        Bar,
        Baz
    }
    public record MyDTO(int Id, MyEnum Enum);

controller

    public class FooController : Controller
    {
        [EnableQuery]
        public IQueryable<MyDTO> Get()
        {
            return new[]
            {
                new MyDTO(1, MyEnum.Bar),
                new MyDTO(2, MyEnum.Baz)
            }.AsQueryable();
        }
    }

page:

    private CGrid<MyDTO> _grid;
    private Task _task;

    Action<IGridColumnCollection<MyDTO>> columns = c =>
    {
        c.Add(p => p.Id);
        c.Add(p => p.Enum);
    };

    protected override async Task OnParametersSetAsync()
    {
        string url = NavigationManager.BaseUri + "odata/foo";
        var query = new QueryDictionary<StringValues>();

        var client = new GridODataClient<MyDTO>(Client, url, query, false, "ordersGrid", columns, 10)
        {
        };
        _grid = client.Grid;

        // Set new items to grid
        _task = client.UpdateGrid();
        await _task;
    }

```

gives result

The JSON value could not be converted to Blackbot.Blazor.Shared.MyDTO. Path: $.value[0].Enum | LineNumber: 0 | BytePositionInLine: 109.

@CupcakeThief
Copy link
Contributor Author

aha..
GridBlazor\CGrid.cs
l.1150 (+1111)

ODataDTO<T> response = await HttpClient.GetFromJsonAsync<ODataDTO<T>>(Url + allParameters);

It's not customising the deserialiser.

Might need adding here, too?
ODataService.cs

public async Task<T> Get(params object[] keys)
{
    string url = GetUrl(_grid, _url, keys);
    return await _httpClient.GetFromJsonAsync<T>(url);
}

rgentry09 pushed a commit to rgentry09/ERP-ASP.NET that referenced this issue Jul 10, 2023
rgentry09 pushed a commit to rgentry09/ERP-ASP.NET that referenced this issue Jul 10, 2023
dev0926 added a commit to dev0926/gridNET that referenced this issue Feb 21, 2024
dev0926 added a commit to dev0926/gridNET that referenced this issue Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants