Replies: 1 comment
-
not to be nitpicker (just to clarify), these are properties and not fields. when you define a new property, you should initialize it with a default value otherwise it will be null in case of nullable types, and not optional |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Instead of having to use field initializers for default values for a config it would be nice to override a method that creates the desired default values for fields.
For example:
You have a field inside your class that is optional to include in the config.
In the current implementation if this field is not initialized the value in the default config will be empty, and the user making changes to the default configuration will not necessarily understand how to format it to make it work as intended.
If you define the default value using a field initialization but the users config file is now missing this "optional" field, the config that loads will use the initialized value from the field initialization which is not always what you want.
Example:
![image](https://private-user-images.githubusercontent.com/1338057/337140559-f2321757-5c60-4520-acea-7b794ef9f35e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2OTYwNzQsIm5iZiI6MTcyNDY5NTc3NCwicGF0aCI6Ii8xMzM4MDU3LzMzNzE0MDU1OS1mMjMyMTc1Ny01YzYwLTQ1MjAtYWNlYS03Yjc5NGVmOWYzNWUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjZUMTgwOTM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2Q3NDg4OGUyN2VkZTkxMDdmYzcyOGE5NmQ1YjZmNTNlNDcwYjE3N2ZiZTliMDA1YjZjZThmOTQ4OWIxZmY5NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.iIz9gBXM181S8S78Rn4_dCfD-rgEe55ZHPARu5DNYzs)
If the users config is missing this field, the field will be initialized like above. To work around this, they have to define
MapConfigs
in their config file but make it empty so that the deserializer will override the default instance of this field.Beta Was this translation helpful? Give feedback.
All reactions