Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for fields and null values #2

Merged
merged 19 commits into from
May 25, 2020
Merged

Adds support for fields and null values #2

merged 19 commits into from
May 25, 2020

Conversation

skigrinder
Copy link
Contributor

@skigrinder skigrinder commented May 17, 2020

Adds support for fields and null values which fail in the test application

Motivation and Context

Required to ensure serialization and deserialization work correctly.

How Has This Been Tested?

Against the included test program.

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@nfbot
Copy link
Member

nfbot commented May 17, 2020

Hi @skigrinder,

I'm nanoFramework bot.
Thank you for your contribution!

A human will be reviewing it shortly. 😉

@CLAassistant
Copy link

CLAassistant commented May 17, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@networkfusion networkfusion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the comments. Also, why have you created a new project and not used the sample one?

@@ -55,7 +55,7 @@ public static void Main()

DoArrayTest();
DoSimpleObjectTest();
DoFloatNaNObjectTest();
//DoFloatNaNObjectTest();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the test, even if it fails, so that people can see...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you create the Json.Test project?

Copy link
Member

@networkfusion networkfusion May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the json nfproj seems to be totally recreated in your PR (not the test one)... not sure why that is...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it probably has to do with the nerdbank NuGet. I had updated to the latest beta version and didn't realized this would cause problems. I tried to revert back to the stable version and things got really messed up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out the issues with Json.Test - it now builds

@@ -13,7 +16,7 @@ internal static class DebugHelper
// Used this a lot in the effort to get Array serialization & deserialization working
public static void DisplayDebug(string displayString)
{
#if DEBUG
#if NANOFRAMEWORK_DISPLAY_DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoFramework will automatically show the Console.WriteLine when #if DEBUG is used and the lib is in debug mode, there is no reason for NANOFRAMEWORK_DISPLAY_DEBUG here. Please revert. (note, it is now preferable to use Debug.WriteLine which removes the need for this function entirely)

Copy link
Contributor Author

@skigrinder skigrinder May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about changing everything to Debug.WriteLine, but there's a lot of output.
Don't most people work in Debug mode?
If so, the serialize/deserialize output would be annoying.
I thought NANOFRAMEWORK_DISPLAY_DEBUG would be a convenient way to turn on the lib output if we ever need to work on it again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how Debug works when referencing published nugets… @josesimoes will Debug be output when published and referenced?

{
dt = DateTimeExtensions.FromASPNetAjax(sdt);
}
else
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try and remove any whitespace changes, they make reviewing a lot harder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was an attempt to conform to the coding standard.

@@ -397,15 +464,15 @@ private static JsonToken Deserialize()
throw new Exception("unexpected lexical token during json parse");
}
return result;
}
} // end of Deserialize()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for comments like this, as VS can easily shrink functions and this does not conform to the C# nF code style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -464,7 +531,7 @@ private static JsonArrayAttribute ParseArray(ref LexToken token)
}
var result = new JsonArrayAttribute((JsonToken[])list.ToArray(typeof(JsonToken)));
return result;
}
} // end of ParseArray()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for comments like this, as VS can easily shrink functions and this does not conform to the C# nF code style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -520,7 +587,7 @@ private static JsonToken ParseValue(ref LexToken token)
}

throw new Exception("invalid value found during json parse");
}
} // end of ParseValue()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for comments like this, as VS can easily shrink functions and this does not conform to the C# nF code style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -72,11 +77,11 @@
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<Import Project="..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.2.5-beta\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.2.5-beta\build\Nerdbank.GitVersioning.targets')" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont update this nuget, we need the stable one for the release pipeline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This created some trouble for me. I'll revert back to 3.1.91

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.2.5-beta\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.2.5-beta\build\Nerdbank.GitVersioning.targets'))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont update this nuget, we need the stable one for the release pipeline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

<package id="nanoFramework.System.Collections" version="1.0.1-preview.6" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Text" version="1.0.0-preview.16" targetFramework="netnanoframework10" />
<package id="nanoFramework.Windows.Storage.Streams" version="1.8.2-preview.5" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.1.91" targetFramework="netnanoframework10" developmentDependency="true" />
<package id="Nerdbank.GitVersioning" version="3.2.5-beta" targetFramework="netnanoframework10" developmentDependency="true" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont update this nuget, we need the stable one for the release pipeline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

else if (memberProperty.Value is JsonValue)
{
// Don't need any more info - populate the member using memberSetMethod.Invoke()
DebugHelper.DisplayDebug($"{debugIndent} memberProperty.Value is JValue");
if (memberType != typeof(DateTime))
if (memberType != typeof(DateTime))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

{
DateTime dt;
var sdt = ((JsonValue)memberProperty.Value).Value.ToString();
if (sdt.Contains("Date("))
if (sdt.Contains("Date("))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@@ -436,13 +503,13 @@ private static JsonObjectAttribute ParseObject(ref LexToken token)
throw new Exception("unterminated json object");
}
return result;
}
} // end of ParseObject()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@networkfusion networkfusion changed the title skigrinder - added support for fields and null values Adds support for fields and null values May 21, 2020
@networkfusion
Copy link
Member

@skigrinder , keep pushing to your branch, the changes will make the comments outdated (due to your changes) so that we are automatically aware...

@josesimoes josesimoes added the Type: Bug Something isn't working label May 22, 2020
Fixes some style issues
Reverts debug def (as not important for most users)
@networkfusion
Copy link
Member

@skigrinder , I hope you dont mind, but I have cleaned up the rest of the remaining issues... I just need to test it now, and then it can be committed. Hopefully the commits I have made will help you with future PR's. The main (remaining) issue was that you had created seperate solutions for each project, when you should have just opened the existing one...

@networkfusion
Copy link
Member

In regards to the debug helper, (as confirmed by @josesimoes (in private cononversation)) nugets are only published as "release", so it is wise not to use a custom debug def...

@networkfusion networkfusion merged commit e3d7953 into nanoframework:develop May 25, 2020
@skigrinder
Copy link
Contributor Author

@networkfusion, thanks for the effort.
I thought I had cleaned up all the issues we talked about.
Did they not get pushed up or did I miss some?

Glad to know that the NuGets are all built as 'Release'.
Should I get rid of the debug helper in favor of Debug.WriteLine() ?
This would make the code cleaner but I don't want to hold up the show.

@networkfusion
Copy link
Member

@skigrinder not to worry, it didn't take long to do the last little bits, and we are glad for the contribution. plus, you enjoy the fact that the PR was of your making... Yes, feel free to convert to Debug.WriteLine in another PR (using another branch).

@skigrinder
Copy link
Contributor Author

skigrinder commented May 25, 2020 via email

@networkfusion
Copy link
Member

Since you didn't use a different branch, you will need to do something like https://ardalis.com/syncing-a-fork-of-a-github-repository-with-upstream (although on the develop branch instead of master. The althernative is to "delete" your fork and start again (it will cause no issues now that this PR is closed). I have done both in the past... But for next time, make sure you create a new branch when making changes in your own fork, and then you can just switch to develop pull the changes and merge onto your new branch whenever nF changes... there is lots of info out there, just google it...

@skigrinder
Copy link
Contributor Author

skigrinder commented May 26, 2020 via email

@networkfusion
Copy link
Member

You need to create the branch in your fork. The branch will be available to nF when a PR is raised. At that point, the branch will be merged into this repos develop branch...

@skigrinder
Copy link
Contributor Author

skigrinder commented May 26, 2020 via email

@skigrinder
Copy link
Contributor Author

skigrinder commented May 26, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants