Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

[Prototype] Use JsonDeserializer in Microsoft.Framework.Runtime #1779

Merged
merged 1 commit into from
May 12, 2015

Conversation

troydai
Copy link
Contributor

@troydai troydai commented May 5, 2015

Address issue: #30

JsonDeserializer is entirely internal to Microsoft.Framework.Runtime.

Logic of writing lock file is moved to Microsoft.Framework.PackageManager, where Newtonsoft.Json will be referenced.

All exceptions are updated.

Unit tests are added to covert JsonDeserializer

@ghost ghost added the cla-already-signed label May 5, 2015
{
return ValueAs(key, value =>
{
if (value != null && value is JsonBoolean)
Copy link
Contributor

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;
Copy link
Member

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.

@Eilon
Copy link
Member

Eilon commented May 5, 2015

BTW several other style issues (multiple types per file, var, etc.) but I won't comment on them further because this is a prototype.

@victorhurdugaci
Copy link
Contributor

So this json deserializer doesn't support comments? That's a breaking change

@troydai
Copy link
Contributor Author

troydai commented May 5, 2015

Two features are required not to break current scenario:

  1. Comments support;
  2. Redundant trailing comma.

@troydai
Copy link
Contributor Author

troydai commented May 5, 2015

@davidfowl @Eilon @victorhurdugaci
There are quite a few implementations I want to improve, but not until we have a evaluation on the prototype and decide whether we want to move forward with additional features.

@Eilon
Copy link
Member

Eilon commented May 5, 2015

@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.

@victorhurdugaci
Copy link
Contributor

Then we need to update some project.json files like this one: https://github.com/aspnet/MusicStore/blob/dev/src/MusicStore/project.json

@Eilon
Copy link
Member

Eilon commented May 5, 2015

@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.).

@troydai
Copy link
Contributor Author

troydai commented May 5, 2015

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 MoveNext and MovePrev, which open to potential bugs. Besides that the deserializing logic itself is intact.

@Eilon
Copy link
Member

Eilon commented May 5, 2015

@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).

@Eilon
Copy link
Member

Eilon commented May 5, 2015

@troydai great!

@davidfowl
Copy link
Member

Feels like the parser needs to be trimmed down for things we don't need to care about:

  • Utf16StringValidator.cs (do we need it)
  • Json* types (why do we need them?), Dictionary<string, object>, string, int, primitive types should be enough right?
  • Depth checking (why bother)? Do we need this safety?

@troydai
Copy link
Contributor Author

troydai commented May 5, 2015

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();
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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 ?

Copy link
Contributor Author

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:

{}
{}

@troydai
Copy link
Contributor Author

troydai commented May 11, 2015

@Eilon @victorhurdugaci

@troydai
Copy link
Contributor Author

troydai commented May 11, 2015

Rebased and ready for reviews.

@Eilon
Copy link
Member

Eilon commented May 11, 2015

:shipit: for me - I don't think that me looking at it anymore will yield anything useful 😄

@troydai
Copy link
Contributor Author

troydai commented May 11, 2015

Yeah. I collected one squirrel now.

if (exception is JsonDeserializerException)
{
return new FileFormatException(exception.Message, exception)
.WithFilePath(filePath)
Copy link
Contributor

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 :)

@victorhurdugaci
Copy link
Contributor

🚢 it

@troydai
Copy link
Contributor Author

troydai commented May 11, 2015

All right, I got a squirrel sitting on a ship now. All what I need is @davidfowl screaming at me one more time....

@JamesNK
Copy link
Member

JamesNK commented May 12, 2015

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.

@davidfowl
Copy link
Member

@JamesNK This parser is really for 2 things:

  1. Don't use JSON.NET before the app's dependency graph loads
  2. Performance loading 3 known file formats, project.lock.json, project.json, global.json.

We're going to use JSON.NET for everything else.

@JamesNK
Copy link
Member

JamesNK commented May 12, 2015

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.

@davidfowl
Copy link
Member

@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.
Copy link
Member

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.

Copy link
Contributor Author

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.

@davidfowl
Copy link
Member

A few minor comments but :shipit: it looks great!

I have some things to follow up on after this initial checkin to do with performance 😄 !

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.
@troydai troydai merged commit f0a852a into dev May 12, 2015
@troydai troydai deleted the trdai/json branch May 12, 2015 21:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.