How to hide properties of an ASP.NET Core model entity only in JSON rendering?

0

I'm starting studies with ASP.NET core Web Api, and I'm implementing the User class, which has a Password property. Of course I do not want the password to be visible in aps JSONs.

I have been researching a lot, I read about IgnoreDataMember, DataContract, DataMember etc ... but their behavior is a bit too radical, ie when I add an IgnoreDataMember annotation in the password property it does not display the password on the User object, but also can not bind the User Password property when it comes to a POST request for example.

I would like a way that this property did not appear in the response JSON, but was still available for use within the system.

Before concluding, I know the ViewModel pattern, and I know that I can create a class with only the parameters I want to display, but honestly, I find this design pattern extremely verbose (it's written too much to implement). I know that I will ultimately use this myself, but I would like to have another more elegant option.

Thank you for your attention!

    
asked by anonymous 15.12.2017 / 19:28

0 answers