Skip to content

Default Configurations

zml edited this page Jan 10, 2022 · 1 revision

When building an application, many developers will want to provide their users a pre-populated configuration to start off from. There are a few ways to do this, some with the assistance of Configurate, and some without. Each method has its own tradeoffs, and the best choice may be different for each application. These options are presented in no particular order.

Plain file copy

  1. just copy a fully formed file if the configuration doesn't exist, and never write from within your application code

pros: Simple, gives you more control over the file layout

cons: once the configuration has been written, it can't be automatically evolved if you want to change format or add/remove keys

  1. Use default fields and the @Comment annotation with the object mapper

pros: everything is in one place, able to be updated automatically

cons: for some loaders, certain formatting details or comments may be lost. also requires using the object mapper

  1. Have a reference configuration file distributed with your project, which is merged with the user configuration file

pros: doesn't require object mapper, allows evolving the file over time

cons: user formatting may be lost depending on the loader, requires maintaining two sources of information

  1. with copydefaults enabled, provide defaults for every get operation

this is kinda awkward, but works if you don't want to use the object mapper -- same cons of potentially losing formatting

Clone this wiki locally