Created
December 1, 2021 18:24
-
-
Save mcalavera81/fa4402e33eceae86680524d178e92b52 to your computer and use it in GitHub Desktop.
Reading YAML files
This file contains 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
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); #B MapType mapType = | |
mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class); | |
MapType yamlConfigType = mapper .getTypeFactory() .constructMapType( HashMap.class, mapper.getTypeFactory().constructType(String.class), mapType); | |
Path configFilePath; | |
Map<String, Map<String, Object>> config = mapper.readValue(configFilePath.toFile(), yamlConfigType); | |
AuthStrategy authStrategy = null; | |
Map<String, Object> authConfig = config.get("auth") | |
if (authConfig.get("strategy").equals(USERNAME_PASSWORD_STRATEGY)) { | |
authStrategy = new UsernamePasswordAuthStrategy( (String) authConfig.get("username"), (String) authConfig.get("password")); | |
} else if (authConfig.get("strategy").equals(TOKEN_STRATEGY)) { | |
authStrategy = new TokenAuthStrategy((String) authConfig.get("token")); } | |
=========== | |
auth: | |
strategy: username-password username: user | |
password: pass | |
=========== | |
auth: | |
strategy: token | |
token: c8933754-30a0-11eb-adc1-0242ac120002 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment