Git Product home page Git Product logo

Comments (2)

elgonzo avatar elgonzo commented on September 8, 2024

There is no bug here.

First,

{""}

serializer will not generate an output like {""} (which by the way would not be valid json either).
For instances of your example class SomeClass, the serializaer will create an empty json object {}.

When [JsonIgnore] is used on a public field it should be ignored per OptOut.

Yes, and it does exactly that already. The [JsonIgnore] on the activeProject field leads to this field not being in the json data.

IList CreateProperties(Type type, MemberSerialization memberSerialization)

If you look at the JsonProperty instance representing the activeProject, you'll notice that its JsonProperty.Ignored property is set to true (which then leads to the serializer excluding it from serialization).

Should not create a json file.

That's an incorrect expectation. You serialize a SomeClass instance, hence you should get a json output representing this instance. The result being an empty json object {} is correctly representing a SomeClass instance, as there are no members in SomeClass participating in serialization. (Any json result deviating from this would be either due to a custom contract resolver or a custom json converter altering the behavior of the serializer.)

(P.S.: I am not associated or related to the Newtonsoft.Json project and its author/maintainer. I am just a fellow user of the library... or perhaps former user, as these days it's pretty much always STJ over Newtonsoft.Json.)

from newtonsoft.json.

BeachyHeadCode avatar BeachyHeadCode commented on September 8, 2024

@elgonzo as mentioned in my initial entry there is no json example. The {""} is me implying that with the text above it. If that is what you got hung up on then ignore {""} as that means nothing to me or anyone else.

[JsonIgnore] does not function as intended. CreateProperties returns the field with [JsonIgnore] attribute when the field is public. That does not comply with OptOut. It should be excluded but is not. I would give you screenshots of the objects, but my company blocks the upload of images to GitHub. Only the access modifier of the field is being acknolleged. If i change:

public class SomeClass {
    [JsonIgnore]
    public string activeProject = string.Empty;
}

To:

public class SomeClass {
    [JsonIgnore]
    private string activeProject = string.Empty;
}

It won't show. Same with:

public class SomeClass {
    private string activeProject = string.Empty;
}

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.