Comments (2)
Not a bug. However, you are not the first and will not be the last whose intuitive assumptions about Newtonsoft.Json's serialization behavior is in conflict with the actual default behavior of Newtonsoft.Json. See #2923 (comment) and also the documentation for JsonSerializerSettings
regarding the default serialization setting values (https://www.newtonsoft.com/json/help/html/SerializationSettings.htm#ObjectCreationHandling or https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonSerializerSettings.htm).
In essence, you would have to configure the serialization setting ObjectCreationHandling.Replace
to match the deserializer behavior with your expectations.
I hope this helps teh next version fix it
That is astronomically unlikely to happen, considering that the solution to this problem is to configure the (de)serializer appropriately, which is easy to do. Changing the default behavior of the (de)serializer, one that is already established for a long time, would be an breaking change; basically a no-go, considering how many (legacy) projects and deployments use Newtonsoft.Json.
We've had to hotfix by removing json.net alltogether unfortunately.
If this implies you migrated to System.Text.Json, then that's in my opinion the best solution by far, and there should be no reason to go back to Newtonsoft.Json.
from newtonsoft.json.
I'm very confused becasue this started happening without us realising it, and after so many years i had no idea about the behaviour of ObjectCreationHandling.
To be honest we're only switching away because first I never knew that behaviour would express itself in such a way, and i hadn't read https://www.newtonsoft.com/json/help/html/SerializationSettings.htm in as long as i started using your library! My fault on this one.
Secondly, we have a custom json-ld serialializer we built on top of Utt8Writer (the non MS one but I understand the current MS one is based on it and maybe has the same author), so it made sense to make the move.
May I suggest that, at least for me as a non-english speaker, https://www.newtonsoft.com/json/help/html/SerializationSettings.htm did not quite make me expect what the bheaviour was, and that I'd be happpy to contribute some content if you have FAQs or elsewhere so it is more obvious that on a nested object reuse would be used even if the content is different?
I got also extremely confused by the fact that it used the last one rather than the first one it found.
Either way let me know if I can help. I'll close the bug as invalid as it is properly documented.
from newtonsoft.json.
Related Issues (20)
- .NET 9.0 and Binary Formatter being removed HOT 1
- Documentation web site is down HOT 1
- JsonConverter for struct not used for nullable fields when passed through JsonSerializerSettings HOT 2
- Custom Converter fails when both decimal and doubles are present HOT 3
- Json data parsing in MAUI .NET 8
- StringEnumConverter.AllowIntegerValues confusing documentation
- ToString method with Formatting.None returns "null" instead of empty string for null values HOT 2
- Nullable DateTime in Dictionary can't use custom converter to convert into empty string HOT 3
- Can't de-serialise decimals having no leading zero (regression between NewtonSoft.Json 9.0.1 and 10.0.1) HOT 2
- Incorrect parsing of JSONPath query HOT 2
- Opt-out of JTokenType.Guid (and other "custom" JTokenTypes) HOT 1
- Serialized C# class numeric string is partially converted to float on serialization and deserialization (used to be fine) version 13.0.0.0 HOT 2
- DefaultContractResolver and fluent configuration
- JsonProperty required allowed but not respected on record parameters HOT 2
- Deserializing unclosed object to JObject
- Support for JsonSerializer.Context when StreamingContext is removed HOT 2
- Deserializing with `NullValueHandling.Ignore` for a type with constructor parameters doesn't ignore null values 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
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.