applejag / Newtonsoft.Json-for-Unity.Converters

Converters of common Unity types for Newtonsoft.Json. Goes hand in hand with jilleJr/Newtonsoft.Json-for-Unity
https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters
MIT License
332 stars 37 forks source link

Suggestion: make UnityConverterInitializer.defaultUnityConvertersSettings accessible. #58

Closed Wouterdek closed 3 years ago

Wouterdek commented 3 years ago

Description

After building my project, JsonConvert.DefaultSettings is not set upon startup by this package. It works fine in the editor but, probably due to my project layout, the initialization doesn't work properly in builds. This is fine, I don't care, but I would like to be able to use the default config myself. So, instead of relying on JsonConvert.DefaultSettings, I would like to manually pass UnityConverterInitializer.defaultUnityConvertersSettings to the json calls I'm making.

Motivation

Unfortunately, it seems UnityConverterInitializer.defaultUnityConvertersSettings is inaccessible because UnityConverterInitializer is an internal class. I have the option of manually creating a JsonSerializerSettings, but I just want the default settings from this package, without having to worry about misconfiguring it or updating it for future releases of this package. I can access UnityConverterInitializer.defaultUnityConvertersSettings using reflection, but that is not very nice.

Suggested solution

Either make UnityConverterInitializer public, or create a new public type that exposes defaultUnityConvertersSettings or CreateJsonSettingsWithFreslyLoadedConfig()

Thank you!

applejag commented 3 years ago

Hi @Wouterdek, thanks for the great suggestion! I did not really realize that it's marked as internal. In my mind I coded it in a way so it would be possible to alter it via code as well.