Comments (5)
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.
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.
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.
I believe you could override this by creating your own contract resolver.
from newtonsoft.json.
@asgerhallas did you implement your own contract resolver? (I need case sensitive deserialization)
from newtonsoft.json.
Related Issues (20)
- Add support for the four `System.Text.Json` types HOT 1
- Can't deserialize object just serialized. HOT 2
- Serialize/Deserialize not working in Release build HOT 7
- Valid JsonPath expression `$.*` on Json Array results in exception HOT 1
- Crash on android aarch64 (Using Unity il2cpp) HOT 1
- Read JObject Property: System.Security.VerificationException: Operation could destabilize the runtime HOT 1
- array.length jsonpath for the selectToken method returned null instead of count HOT 1
- String Property With Math Function Not Deserialized Correctly HOT 1
- The C# `required` modifier should trigger `Required.Always` behaviour HOT 3
- Provide a centralized way to disable ExpressionValueProvider or fix DynamicCodeGeneration check HOT 6
- JsonTextWriter produces invalid JSON when Unicode char \u201d present in string HOT 1
- Unexpected exceptions during deserialization due to missing constructor name HOT 1
- Non-Null default value leads to invalid cache value being assigned HOT 2
- PopulateObject won't throw Exception on invalid JSON
- Inquiry Regarding Privacy Policy in Newtonsoft.Json HOT 2
- Multiple JsonSerializerSettings are sharing same CamelCasePropertyNamesContractResolver cache HOT 1
- Deserialize decimal same code results not match HOT 3
- Generic Attributes -> Generic types are not valid. HOT 6
- MissingMemberHandling.Error doesn't throw when property is set with jsonignore HOT 1
- Object duplication when deserializing class with initial static value assigned. HOT 1
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.