-
-
Notifications
You must be signed in to change notification settings - Fork 42
A new JsonConverterOptions attribute for new converter management #97
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
base: master
Are you sure you want to change the base?
A new JsonConverterOptions attribute for new converter management #97
Conversation
…operty Hidden to hide a converter from converters settings
This is a fine idea, @Erifirin. I like it! I have not looked at the implementation yet, but I would say it would be better with a more explicit Adding this feature inside a generic options/settings container like this makes it a little ambiguous, and I wouldn't bet on us supporting arbitrary compile-time settings to converters using attributes. That would be a weird way to control things when attributes anyways already require you to have code access. |
Splendid. Glad to hear you liked the idea.
That's the point. Sometimes control should be in the hands of the converter's author.
Hmm.. Ok. Sounds good and looks clearer. I would prefer |
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.
Nice work! Just some small comments. And now I have to figure out how to get my CI/CD to work again 🤔
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class HideInJsonConverterSettings : Attribute { } |
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.
Need a doc comment on this type to explain how it works and why you would use it
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'll try. But I'm not good at English))) Maybe you'll want to do it yourself later.
var hiddenConverterRegistered = UnityConverterInitializer.defaultUnityConvertersSettings.Converters | ||
.Any(x => x.GetType() == typeof(HiddenConverter)); |
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.
To make sure this works, could you also add a converter like VisibleConverter
that doesn't have the attribute?
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.
Easy. Just give me a couple of minutes)
@applejag I've done. So what about problems with CI/CD? Is it because of my HiddenConverterTests? |
I don't actively develop this repo so I always forget how to work with the CI/CD pipelines. And I don't use Unity anymore so every time I do stuff here I have to reinstall a bunch of stuff. But I'll look into it later as I'm working and I need to fully sit down with this and dedicate an hour before I feel comfortable merging and releasing anything |
Hello again.
Sometimes when developing a shared library I need to create a public json converter that does a specific job. This converter is not intended for general use and must be used explicitly by manually marking fields/properties with the attribute
[JsonConverter(<type>)]
(or by using customJsonSerializerSettings
). The problem is that I can't set such a limitation on my side. And without it, I can only hope that in each project my converter will be manually disabled in converters settings. But this approach is dangerous and inconvenient because it requires constant monitoring and maintenance of this list.As an alternative, I propose to introduce a new attribute
JsonConverterOptions
with one optional property for now -Hidden
(more properties can be added in future). If it istrue
, the converter is ignored inUnityConverterInitializer
, is not displayed in converters settings and is not used globally even ifAuto Sync Converters
option is enabled.And use case:
What do you think?