-
Notifications
You must be signed in to change notification settings - Fork 636
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
DYN-7278: Fix dictionary preview by adding support for more types #15750
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec9ef14
fix dictionary preview by adding support for more types
aparajit-pratap ab6bad8
revert assemblyinfo
aparajit-pratap 5fb2728
process json object for preview
aparajit-pratap 4569a81
cleanup
aparajit-pratap 432af98
add tests for byte and uint previews
aparajit-pratap 688332e
add test for JSON preview
aparajit-pratap 836f3f9
remove bad test
aparajit-pratap daa15f2
rename nodes
aparajit-pratap 28b4f3d
review comments
aparajit-pratap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,15 @@ private static string GetStringFromObject(object obj) | |
case TypeCode.DateTime: | ||
return ((DateTime)obj).ToString(PreferenceSettings.DefaultDateFormat, CultureInfo.InvariantCulture); | ||
case TypeCode.Object: | ||
if (obj is byte[] byteArray) | ||
aparajit-pratap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Encoding.UTF8.GetString(byteArray); | ||
return ObjectToLabelString(obj); | ||
case TypeCode.Byte: | ||
return ((byte)obj).ToString(CultureInfo.InvariantCulture); | ||
case TypeCode.UInt32: | ||
return ((uint)obj).ToString(CultureInfo.InvariantCulture); | ||
case TypeCode.UInt64: | ||
return ((ulong)obj).ToString(CultureInfo.InvariantCulture); | ||
default: | ||
return (string)obj; | ||
}; | ||
|
@@ -313,6 +321,12 @@ private string GetDisplayType(object obj) | |
return nameof(TypeCode.Object); | ||
case TypeCode.String: | ||
return nameof(TypeCode.String); | ||
case TypeCode.Byte: | ||
return nameof(TypeCode.Byte); | ||
case TypeCode.UInt32: | ||
return nameof(TypeCode.UInt32); | ||
case TypeCode.UInt64: | ||
return nameof(TypeCode.UInt64); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe the type returned from |
||
case TypeCode.Empty: | ||
return String.Empty; | ||
default: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
a couple thoughts.
ToObject()
calls. It's not clear to me exactly what types this allows deserialization of.I think the default deserialization calls use a secure serializer
(TypeNameHandling = None)
, but I am not sure, it might be good to make it explicit by using a serializer here with settings that encode that specifically - for example:Dynamo/src/DynamoCore/Models/DynamoModel.cs
Line 2158 in 3d8a262
IMO this kind of thing becomes more important now that we have to support DaaS - though I guess maybe this code is never even present on the service? (wpf?)
Where is this type coming from? The Forma nodes? Personally I feel we should ditch newtonsoft everywhere and instead use the built in system.text.json - it's harder to screw up security using it (though not impossible)
I have not thought about it much - but wouldn't it be nice if packages could provide their own watch handlers?
why are both dictionary and this newtonsoft parsing done in the object handler instead of defining more specific overloads - was there a performance reason for this?
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.
NewtonSoft.Json JObject
types that are coming mainly from Forma elements represented as JSON. As of now, I'm not sure what other nodes exist that output such types that have preview issues but so far, I'm seeing this issue only with the Forma nodes. TheJObject
seems to have a structure similar to dictionaries or key-value pairs so it just seems natural to be able to convert them to a form such that they can be previewed such as dictionaries.I'm not sure I understand. What exactly are you referring to byobject handler
andoverloads
?I think I see what you mean. No particular reason for doing it this way. I can add an overload for
ProcessThing
to handleJObject
and maybe another for Dictionary, if that's what you're alluding to.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.
These changes seem to be the first step in trying to support NewtonSoft types as native dynamo types.
If JObjects are passed around between nodes, do you foresee any other nodes/functionality that might not work with this type?
If we want to favor more system.text.json instead of Newtonsoft, I assume we'll encounter similar system.text.json types (like JsonElement and JSonDocument). Should we try to support these at the Proto level in the Marshaler code?
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 kind of like the
packages could provide their own watch handlers?
idea. Some packages might bring their own magic types, and would be nice if they could specify the way Dynamo presents the data.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.
@pinzart90 these changes are only affecting the node previews for these types at the UI level and are not related to marshaling types so in that sense IMO these changes are safer. In order to support System.Text.Json, yes, I believe we'll need to add support for it here as well although I don't think anything specific would need to be done in the marshaler.