Comments (2)
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.
@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)
- Json.NET deserializes nested types using only the last entry in the nested array HOT 2
- error CS0104: 'Func<,>' is an ambiguous reference between 'Newtonsoft.Json.Serialization.Func<T, TResult>' and 'System.Func<T, TResult>' HOT 5
- Exception during deserialization with TypeNameHandling = TypeNameHandling.All a json that was saved by browser HOT 2
- Could not determine JSON object type for type System.Collections.Generic.KeyValuePair HOT 1
- Unity cyclic references of Unity objects HOT 2
- NullReferenceException in JsonSerializer.GetMatchingConverter(IList<JsonConverter> converters, Type objectType) HOT 7
- Ignoring JsonProperty Name HOT 2
- [Enhancement] when serializing/deserializing a netstandard lib used in .net framework/ net core
- JsonConvert.DeserializeObject appends value for no reason HOT 2
- Ask for the "PrivacyInfo.xcprivacy" required by Apple
- Could not create an instance of type X. Type is an interface or abstract class and cannot be instantiated. HOT 2
- Problem with Deserialize number like 0...8 and 0...9 HOT 2
- deserialize object Ignore case HOT 1
- Deserializing object of missing class as it's Base class (C#) HOT 1
- Source code version problem HOT 1
- [Feature Request] MissingMemberHandling attribute HOT 4
- JsonConvert.DeserializeObject using $type does not (at least for the root object) not use the converter HOT 3
- JsonConverter is called despite that CanConvert returns false, and despite that the target type isn't decorated with JsonConverterAttribute HOT 6
- ReferenceLoopHandling.Ignore unexpectedly skips objects - false positive if Equals/HashCode result is the same
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from newtonsoft.json.