Giter Site home page Giter Site logo

Comments (2)

elgonzo avatar elgonzo commented on June 20, 2024

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.

serialseb avatar serialseb commented on June 20, 2024

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)

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.