Coder Social home page Coder Social logo

Comments (1)

elgonzo avatar elgonzo commented on May 23, 2024

That there is no exception being thrown for ignored members is logical and expected behavior and no bug. Because the member is not missing, it is just ignored.

One relatively easy way to make an ignored member go "missing" is to create your own contract resolver derived from DefaultContractResolver, which removes ignored properties from the list of properties for an object contract. Something like this, for example:

class IgnoredMembersGoMissingContractResolver : DefaultContractResolver
{
  protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
    => base.CreateProperties(type, memberSerialization)
           .Where(p => !p.Ignored)
           .ToList();
}

I haven't tested this code myself (just written down from the top of my head, and therefore might contain typos or other errors), but it can serve as an illustration of the approach.

Note that the JsonProperty.Ignored value tested here is not only influenced by the JsonIgnoreAttribute, but also by other attributes.

Especially noteworthy is that JsonProperty.Ignored is also set by the JsonExtensionDataAttribute. If you are using this attribute, you will have to test thoroughly whether "blindly" removing the extension data property from the list of serializable properties (as my code example does) has any averse side effects.

from newtonsoft.json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.