unosquare / embedio

A tiny, cross-platform, module based web server for .NET
http://unosquare.github.io/embedio
Other
1.45k stars 175 forks source link

Serializing interfaces doesn't work as expected #541

Closed Sandoun closed 2 years ago

Sandoun commented 2 years ago

Is your feature request related to a problem? Please describe. If the return type of an api route is an interface the serializer/JSON string doesn't account for exposed properties and it sends the whole object.

Describe the solution you'd like It would be nice to serialize only the the exposed properties of the interface.

Describe alternatives you've considered If you serialize as IVerboseUserData with the new System.Text.Json Serializer you get only the exposed props of the interface but this adds boilerplate.

Additional context

For example given the following structure:

public class StoredUserData : IVerboseUserData {

    public string Username { get; set; } = "examplename";
    public string Password { get; set; }

}

public interface IVerboseUserData {

    public string Username { get; set; }

}

And the route

[Route(HttpVerbs.Post, "/self")]
public async Task<IVerboseUserData> GetSelfUser () 

Should only return

{
    "Username" : "examplename"
}
rdeago commented 2 years ago

Hello @Sandoun, thanks for using EmbedIO!

Unfortunately this is not the right place to open an issue about the JSON serializer used by EmbedIO. Please follow this link to file a bug report to the SWAN library.