diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 7a45e8e3..aa0d99ce 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -253,6 +253,37 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(input.Result, deserialized.Result); } + [Test] + public void DeserializeJObjectWithComments() + { + JObject o = (JObject)JsonConvert.DeserializeObject(@"{/*Test*/""A"":/* Test */true/* Test */,/* Test */""B"":/* Test */false/* Test */}"); + Assert.AreEqual(2, o.Count); + Assert.AreEqual(true, (bool)o["A"]); + Assert.AreEqual(false, (bool)o["B"]); + + o = (JObject)JsonConvert.DeserializeObject(@"{/* Test */}"); + Assert.AreEqual(0, o.Count); + + o = (JObject)JsonConvert.DeserializeObject(@"{""A"": true/* Test */}"); + Assert.AreEqual(1, o.Count); + Assert.AreEqual(true, (bool)o["A"]); + } + + public class CommentTestObject + { + public bool? A { get; set; } + } + + [Test] + public void DeserializeCommentTestObjectWithComments() + { + CommentTestObject o = JsonConvert.DeserializeObject(@"{/* Test */}"); + Assert.AreEqual(null, o.A); + + o = JsonConvert.DeserializeObject(@"{""A"": true/* Test */}"); + Assert.AreEqual(true, o.A); + } + [Test] public void JsonSerializerProperties() { diff --git a/Src/Newtonsoft.Json/Serialization/JsonProperty.cs b/Src/Newtonsoft.Json/Serialization/JsonProperty.cs index 32cbfb07..a275557c 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonProperty.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonProperty.cs @@ -39,8 +39,8 @@ namespace Newtonsoft.Json.Serialization { internal Required? _required; internal bool _hasExplicitDefaultValue; - internal object _defaultValue; + private object _defaultValue; private bool _hasGeneratedDefaultValue; private string _propertyName; private bool _skipPropertyNameEscape; diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index db859024..fc7c7f1f 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -236,8 +236,11 @@ namespace Newtonsoft.Json.Serialization if (reader.TokenType == JsonToken.PropertyName) { string propertyName = (string)reader.Value; - if (!reader.Read()) - break; + do + { + if (!reader.Read()) + break; + } while (reader.TokenType == JsonToken.Comment); if (CheckPropertyName(reader, propertyName)) continue; @@ -245,6 +248,10 @@ namespace Newtonsoft.Json.Serialization writer.WritePropertyName(propertyName); writer.WriteToken(reader, true, true); } + else if (reader.TokenType == JsonToken.Comment) + { + // eat + } else { writer.WriteEndObject();