#208 Error reading package.json. The file may be parseable JSON but may#459
#208 Error reading package.json. The file may be parseable JSON but may#459mousetraps merged 1 commit intomicrosoft:masterfrom
Conversation
…SON but may contain objects with duplicate properties
There was a problem hiding this comment.
Is this definitely safe to sometimes fallback to a different method? I see DeserializeObject and JObject.Parse both return different types (Object and JObject respectively).
Also, may the new JObject.Parse now throw different exceptions than those you are handling below? (i.e. do you need to add more handlers for any JObject.Parse failures).
There was a problem hiding this comment.
Yes, it is safe because DeserializeObject actually returns JObject under the covers when no explicit type is specified (JsonConvert.DeserializeObject(...).GetType().FullName returns "Newtonsoft.Json.Linq.JObject")
It's unclear why the two follow different codepaths, though. Perhaps they've fixed this issue in later versions of Newtonsoft.Json, but this workaround will have to suffice for now.
fix #208 Error reading package.json. The file may be parseable JSON but may
|
The public ReaderPackageJsonSource(TextReader reader) {
try {
var text = reader.ReadToEnd();
try {
// JsonConvert and JObject.Parse exhibit slightly different behavior,
// so fall back to JObject.Parse if JsonConvert does not properly deserialize
// the object.
Package = JsonConvert.DeserializeObject(text);
} catch (ArgumentException) {
Package = JObject.Parse(text);
}
} catch (JsonReaderException jre) {
WrapExceptionAndRethrow(jre);
} catch (JsonSerializationException jse) {
WrapExceptionAndRethrow(jse);
} catch (FormatException fe) {
WrapExceptionAndRethrow(fe);
} catch (ArgumentException ae) {
throw new PackageJsonException(
string.Format(@"Error reading package.json. The file may be parseable JSON but may contain objects with duplicate properties.
The following error occurred:
{0}", ae.Message),
ae);
}
}We may also want to fix this test if we are no longer throwing PackageJsonException on duplicate properties. [TestMethod, Priority(0)]
[ExpectedException(typeof(PackageJsonException))]
public void TestParseDuplicateProperty() {
TestFreshPackage("duplicateproperty");
} |
contain objects with duplicate properties
fix #208