0

I'm using ASP.NET Core configured with Newtonsoft's Json.NET to build a text API. I have some objects that are exposed as body for controller actions, and in those objects there are some fields that I want to be "out-only", i.e., that they be included in deserialization but ignored in serialization.

Does Json.NET provides a way to configure that?

I guess I can do that with a custom JsonConverter, but I much prefer to use something out-of-box.

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
  • I would say the usual approach for this is to use _different_ types for output and input. – poke Apr 22 '21 at 23:04
  • 1
    Looks like a duplicate of [Making a property deserialize but not serialize with json.net](https://stackoverflow.com/q/11564091/3744182). agree? (And for the opposite see [Serialize Property, but Do Not Deserialize Property in Json.Net](https://stackoverflow.com/q/31731320/3744182).) – dbc Apr 22 '21 at 23:29
  • Maybe you can use JObject,and choose to deserilaze some fields of JObject. – Yiyi You Apr 23 '21 at 06:19
  • 1
    @dbc you're right! That's what I was looking for! I'm marking my question as a duplicate. – Bruno Brant Jun 12 '21 at 15:55

0 Answers0