-
-
Notifications
You must be signed in to change notification settings - Fork 86
Overhaul ValuesJsonConverter #109
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
Merged
RehanSaeed
merged 19 commits into
RehanSaeed:master
from
Turnerj:refactoring-valuesjsonconverter
Dec 19, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4589fd0
Initial refactor of ValuesJsonConverter
Turnerj 908d9e6
Remove branch logic for casting to OneOrMany
Turnerj bb28364
Improve memory allocation for writes
Turnerj 7df50c5
Updating enum string URI logic
Turnerj 3c34f84
Improving hot path for serialization
Turnerj 33ce37f
Use reader directly instead of JToken
Turnerj f6b24cc
Prevent list allocation for single item
Turnerj 58cc155
Added missing success marker
Turnerj 536a53a
Better support for external types
Turnerj d4f08f5
Add GUID-from-string support
Turnerj a3eb4d3
Adds full support for implicit external types in any namespace
Turnerj 2197c96
Add TimeSpan support for reads
Turnerj b073901
Add support for implicit array conversion
Turnerj 86c4c66
Add write tests for time-related types
Turnerj 1d40a8a
Add support for TimeSpan as ISO 8601 duration
Turnerj 1b0f726
WriteObject to only take individual items
Turnerj 280d05e
TimeSpan converter doesn't need to handle reads
Turnerj a546cac
Moved model classes to separate folder
Turnerj 6dc7814
Updated test naming to make intention clearer
Turnerj 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
Adds full support for implicit external types in any namespace
Implicit external types refers to properties where `Values` or `OneOrMany` refers to a shared interface and not the concrete type. Types must be assignable to `IThing` and will need the full namespace and assembly.
- Loading branch information
commit a3eb4d3148a04d92f6edf38f3b7b3007544e554d
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
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.
What if someone has a custom type? There are devs who have extended Schema.NET with custom schema types built on top of the ones in this project.
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.
Yeah, that is a fair call. The old converter did support any type in the "Schema.Net" namespace so if they added any types in a different assembly to that namespace they would be missed by that type caching.
Uh oh!
There was an error while loading. Please reload this page.
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.
Going through how the old support worked, it is a little interesting. Technically it would only support custom types if the generic arguments to
Values<>orOneOrMany<>listed that type specifically. That is, the custom type wouldn't work if an interface or any parent type was used instead.There was a loophole (I say loophole as I'm not sure it was intended this way) but if you added your type to the namespace "Schema.NET" and put the assembly name in the
@typeproperty (eg. "MyFancyType, MyAssembly"), it would load your custom type. I didn't pick that up at first as it just seemed like that code was just for loading built-in types. It does however work as a good security measure by requiring the namespace as the idea of loading ANY type and instantiating it could be a big security problem (some poorly written types might actually do work in their constructor or at least be very allocate-y).So the code as it stood when you saw it supported the former - if a concrete type is used as a generic argument, it would correctly deserialize to it. To have a concrete type as the generic argument is a bit of a chicken-and-egg scenario as to have a custom property with your concrete type requires a concrete type.
What I've done in 536a53a is extend support to allow the latter - if a type is in the "Schema.NET" namespace, it will look the type up the old way. I've kept the cached type lookup as a means to mitigate some allocations from string concatenation and likely are still faster lookups from the dictionary (though I might try a benchmark testing that specific theory out).
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.
Interesting. I have never tried adding custom types myself but I have seen a few devs mention that they do so, so it would be good to continue to support them.
If we could extend support and lift the limitation on the Schema.NET namespace, I think that would be a nice improvement.
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.
Yeah, happy to try and make support better for custom types though want to be careful we don't start instantiating any-old type otherwise it might open up security issues as we are deriving the type from the payload - might need to look into this more.
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.
As long we check that types inherit from
Thing, I don't think there should be any security issues.