-
Notifications
You must be signed in to change notification settings - Fork 224
[Prototype] Use JsonDeserializer in Microsoft.Framework.Runtime #1779
Conversation
{ | ||
return ValueAs(key, value => | ||
{ | ||
if (value != null && value is JsonBoolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condition could be simplified:
a) as
cast and check on null
or
b) remove null check because if value
is null is
will return false
/// <summary> | ||
/// Current line number in zero-based index. | ||
/// </summary> | ||
public int CurrentLine { get; private set; } = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 is the default value.
BTW several other style issues (multiple types per file, |
So this json deserializer doesn't support comments? That's a breaking change |
Two features are required not to break current scenario:
|
@davidfowl @Eilon @victorhurdugaci |
@victorhurdugaci BTW it's not a "breaking change" in the traditional change because this is all new... but it would be breaking from previous previews, of course. But I agree with @troydai that in the meantime we'll do things one at a time in terms of honing the prototype into production quality. |
Then we need to update some project.json files like this one: https://github.com/aspnet/MusicStore/blob/dev/src/MusicStore/project.json |
@troydai BTW how close is this code to the stuff I sent you? Is the basic parsing logic the same, except that you added the line number support etc.? Are there any other significant differences? I ask because the old parsing code was fairly robust; it was just missing some desirable features (line numbers, comment support, etc.). |
I make sure the the original parsing logic is kept the same, what I added is the line information support. But adding line information support introduces extract logic to |
@victorhurdugaci I think before we take this change we'd have to support comments (assuming we want to continue to support comments, which I hope we do). |
@troydai great! |
Feels like the parser needs to be trimmed down for things we don't need to care about:
|
Types are for line information. By combining the line formation and data in one class, it helps to consume the line information easily. |
private JToken WritePackageReferenceSet(PackageReferenceSet item) | ||
{ | ||
var json = new JObject(); | ||
json["targetFramework"] = item.TargetFramework?.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is possibly assigning null here okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing LockFileWriter
is not in the scope of this PR. This is merely copied from LockFileFormat
to separate read and write.
return string.Format("Invalid Unicode [{0}]", unicode); | ||
} | ||
|
||
internal static string Format_UnfinishedJSON(string nextTokenValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the diff between this and JSON_InvalidEnd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid end is the file finishes to early. This is file finishes to late, there are unprocessed content for example:
{}
{}
Rebased and ready for reviews. |
for me - I don't think that me looking at it anymore will yield anything useful 😄 |
Yeah. I collected one squirrel now. |
if (exception is JsonDeserializerException) | ||
{ | ||
return new FileFormatException(exception.Message, exception) | ||
.WithFilePath(filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this fluent api :)
🚢 it |
All right, I got a squirrel sitting on a ship now. All what I need is @davidfowl screaming at me one more time.... |
If you want ideas for crazy JSON to throw at your reader, there are a ton of examples here: https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs Lots of stuff I read is not technically JSON however. Multi-line strings, date constructors, octal numbers, etc. |
@JamesNK This parser is really for 2 things:
We're going to use JSON.NET for everything else. |
I know. Just letting you know that you either need to handle those examples or fail well. They're what I've built up over the years. |
@JamesNK thanks for the input. Hopefully this will be used on those known quantities and we won't have to handle anything like that. |
@@ -0,0 +1,247 @@ | |||
// Copyright (c) .NET Foundation. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should move the old lock file reader writer logic as a whole to the PackageManager and create a copy of the writer (unshared) in the runtime itself. The PackageManager needs to read the lock file as well but it can use the normal JSON.NET stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right. I'll do that.
A few minor comments but it looks great! I have some things to follow up on after this initial checkin to do with performance 😄 ! |
38faef4
to
e36657d
Compare
1. Implement an internal JSON parser in runtime; 2. Remove dependency on Newtonsoft.Json from Microsoft.Framework.Runtime; 3. Move the LockFileFormat to Microsoft.Framework.PackageManager. Leave a copy of which contains only the reading logic. Rename it to LockFileReader; 4. Make LockFileReader using the internal JSON parser; 5. Updat tests.
Address issue: #30
JsonDeserializer
is entirely internal toMicrosoft.Framework.Runtime
.Logic of writing lock file is moved to
Microsoft.Framework.PackageManager
, whereNewtonsoft.Json
will be referenced.All exceptions are updated.
Unit tests are added to covert
JsonDeserializer