Skip to content

Commit 64eb6c6

Browse files
committed
Updates to #31
I just verified that the applied fix worked and I also cleaned up a unit test that is a todo.. We should get that scenario working (the commented out test). @ejsmith I don't see any problems with this pull request. I think we just need todo some testing.. Do you remember why we weren't doing this before (setting the contract resolver) or was this just an oversight?
1 parent 8ae52be commit 64eb6c6

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

Source/Tests/Serializer/SerializerTests.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.ObjectModel;
44
using Exceptionless.Extensions;
55
using Exceptionless.Json;
6-
using Exceptionless.Json.Serialization;
76
using Exceptionless.Models;
87
using Exceptionless.Serializer;
98
using Xunit;
@@ -80,13 +79,17 @@ public void WillIgnoreEmptyCollections() {
8079
//[Fact]
8180
public void CanDeserializeDataWithoutUnderscores() {
8281
const string json = @"{""BlahId"":""Hello""}";
83-
var settings = new JsonSerializerSettings();
84-
settings.ContractResolver = new LowerCaseUnderscorePropertyNamesContractResolver();
82+
const string jsonWithUnderScore = @"{""blah_id"":""Hello""}";
8583

86-
var m = JsonConvert.DeserializeObject<Blah>(json, settings);
87-
Assert.Equal("Hello", m.BlahId);
84+
IJsonSerializer serializer = GetSerializer();
85+
var value = serializer.Deserialize<Blah>(json);
86+
Assert.Equal("Hello", value.BlahId);
87+
88+
value = serializer.Deserialize<Blah>(jsonWithUnderScore);
89+
Assert.Equal("Hello", value.BlahId);
8890

89-
string newJson = JsonConvert.SerializeObject(m, settings);
91+
string serialized = serializer.Serialize(value);
92+
Assert.Equal(jsonWithUnderScore, serialized);
9093
}
9194

9295
[Fact]
@@ -111,21 +114,4 @@ public class SampleModel {
111114
public ICollection<string> Collection { get; set; }
112115
public SampleModel Nested { get; set; }
113116
}
114-
115-
public class LowerCaseUnderscorePropertyNamesContractResolver : DefaultContractResolver {
116-
public LowerCaseUnderscorePropertyNamesContractResolver() : base(true) { }
117-
118-
protected override JsonDictionaryContract CreateDictionaryContract(Type objectType) {
119-
if (objectType != typeof(DataDictionary) && objectType != typeof(SettingsDictionary))
120-
return base.CreateDictionaryContract(objectType);
121-
122-
JsonDictionaryContract contract = base.CreateDictionaryContract(objectType);
123-
contract.PropertyNameResolver = propertyName => propertyName;
124-
return contract;
125-
}
126-
127-
protected internal override string ResolvePropertyName(string propertyName) {
128-
return propertyName.ToLowerUnderscoredWords();
129-
}
130-
}
131117
}

0 commit comments

Comments
 (0)