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

Alba's built in JSON serialization isn't working for oData endpoints #116

Open
jeremydmiller opened this issue Oct 31, 2022 · 2 comments
Open

Comments

@jeremydmiller
Copy link
Member

More research necessary

@ticky74
Copy link

ticky74 commented Jun 21, 2023

Pretty new to Alba, however I have been using it successfully against OData endpoints with the AspVersioning library. I think there is a bit of a nuance, I'm using Asp.Versioning.OData@7.0.1. Although the OData requests go through controllers, the serialization aligns with the MinimalApiStrategy. In the AlbaHost constructors, the input/output formatters are of type ODataInputFormatter and ODataOutputFormatter, so the MvcStrategy is initialized.

var jsonInput  = findInputFormatter("application/json");
var jsonOutput = findOutputFormatter("application/json");

if (jsonInput != null && jsonOutput != null)
{
    MvcStrategy = new FormatterSerializer(this, jsonInput, jsonOutput);
}

MinimalApiStrategy = new SystemTextJsonSerializer(this);

DefaultJson = MvcStrategy ?? MinimalApiStrategy;

So the DefaultJson is then set to the MvcStrategy and I guess OData isn't a fan.

I have not really tested this against the library, I just grabbed the source and hacked in a couple overloaded constructors and For<>... methods and so far things have been working. Not sure if this helps anyone, or not, but I too had the pleasure of banging my head against the wall with the Asp.Versioning and OData libraries so thought I'd post just in case!

@yulivee
Copy link

yulivee commented Nov 28, 2023

@ticky74 Would you mind sharing your Hack?
Struggeling with a similar Problem, using OData@7.18.0 as a transitive dependency of the ResTier Framework@1.1.0. When Posting Alba supports handing over the MinimalApiStrategy, so we can successfully post json - but when trying to use the ReadAsJson Methods, we get Deserialization Exceptions. Currently stuck testing with ReadAsText which is crude in comparison

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

No branches or pull requests

3 participants