mercredi 27 avril 2016

Asp.Net Web Api : json property names


I have LoginModel:

public class LoginModel : IData
    {
        public string Email { get; set; }
        public string Password { get; set; }
    }

and I have the Web api method

public IHttpActionResult Login([FromBody] LoginModel model)
        {
            return this.Ok(model);
        }

And it's return 200 and body:

{
 Email: "dfdf",
 Password: "dsfsdf"
}

But I want to get with lower first letter in property like

{
 email: "dfdf",
 password: "dsfsdf"
}

And I have Json contrast resolver for correcting

public class FirstLowerContractResolver : DefaultContractResolver
{
    protected override string ResolvePropertyName(string propertyName)
    {
        if (string.IsNullOrWhiteSpace(propertyName))
            return string.Empty;

        return $"{char.ToLower(propertyName[0])}{propertyName.Substring(1)}";
    }
}

How I can apply this?
Thank you!




Aucun commentaire:

Enregistrer un commentaire