-
Notifications
You must be signed in to change notification settings - Fork 175
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
Custom serializer options for WebApiModule #467
Comments
Hello @simohr, thanks for using EmbedIO! While we assess where the bug lies exactly (JSON serialization is part of SWAN, so we may need to open an issue there) here's how to return any given string from a Web API method: [Route(HttpVerbs.Get, "/person")]
public void GetPerson()
{
Response.ContentType = MimeType.Json;
using (var writer = HttpContext.OpenResponseText(Encoding.UTF8, true))
{
writer.Write(serializer.Serialize(new Person() { Name = "SomeName"}));
}
} Notice that the method has a If you omit the second parameter to
This will be usually fine if your client is a browser, but can cause problems if the client relies on the presence of a |
After a little more research we found an alternative solution using the ResponseSerializerCallback. We defined our own callback with the needed settings. Thank you for the response. Here is the solution:
And the SerializationCallback :
|
Well done @simohr! It's refreshing to see someone taking advantage of the customizability of EmbedIO v3. If you want to squeeze out a little more performance, store your serializer options in a |
Is your feature request related to a problem? Please describe.
Hello, since upgrading to embedio version 3.4.3 from version 3.3.3 we have problems with serialization in web controllers. In 3.3.3 we serialize the objects and return them:
However in 3.4.3 the controller has automatic serialization and we no longer need to use our own. This is a problem for us because the JSON objects created are not what we have defined. For example all properties appear with capital letters and slashes are escaped (''):
Now:
Before:
Describe the solution you'd like
Is there a way to stop the automatic serialization or a way to configure its' settings.
The text was updated successfully, but these errors were encountered: