Coder Social home page Coder Social logo

Comments (5)

asgerhallas avatar asgerhallas commented on May 12, 2024

Ok, it does not look like it has anything to do with GetClosestMatchProperty()... Hmm... I'm investegting further, it looks like two different, but similar behaviours I've encountered.

from newtonsoft.json.

asgerhallas avatar asgerhallas commented on May 12, 2024

Ok. I've encountered two different issues.

The Second issue is actually related to GetClosestMatchProperty, when you have a json document with a property that is no longer present in the new representation of the .net class (migrating documents from a Raven database).

The test for this is:

[TestFixture]
public class FallbackToCaseInsensitiveFailsForThisCaseTest
{
    [Test]
    public void CanDeserializeFromJsonWhereTwoPropertyAreSimilarlyNamed()
    {
        var settings = new JsonSerializerSettings
                                         {
                                             ContractResolver = new PrivatesOnly(), 
                                             TypeNameHandling = TypeNameHandling.All
                                         };

        JsonConvert.DeserializeObject<SomethingWithAList>(
        @"
        {      
        ""ints"": {
                  ""$id"": ""469"",
                  ""$type"": ""System.Collections.Generic.List`1[[System.Int32, mscorlib]], mscorlib"",
                  ""$values"": []
                },
                ""Ints"": {
                  ""$id"": ""470"",
                  ""$type"": ""System.Int32[], mscorlib"",
                  ""$values"": []
                }
        }
        ", settings);
    }

    public class PrivatesOnly : DefaultContractResolver
    {
        public PrivatesOnly()
            : base(false)
        {
            DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.NonPublic;
        }
    }

    public class SomethingWithAList
    {
        readonly List<int> ints = new List<int>();
        public IEnumerable<int> Ints
        {
            get { return ints.Where(x => x > 10); }
        }
    }
}

Would you like a pull request with the failing tests? Or is here ok?

from newtonsoft.json.

asgerhallas avatar asgerhallas commented on May 12, 2024

If you even consider them bugs, that is :)

The first one seems to be solvable by some settings - when I get the serializer through RavenDb the issue goes away. But I can't figure out why.

The second one is happening, because I try to deserialize with another contract resolver than I serialized with, so it might not be such a valid case. But it would still be nice to be able to disable the fallback to case insensitive properties and just ignore if a property is missing.

from newtonsoft.json.

JamesNK avatar JamesNK commented on May 12, 2024

I believe you could override this by creating your own contract resolver.

from newtonsoft.json.

andresmoschini avatar andresmoschini commented on May 12, 2024

@asgerhallas did you implement your own contract resolver? (I need case sensitive deserialization)

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.