Skip to content

Instantly share code, notes, and snippets.

@mcalavera81
Created December 1, 2021 18:24
Show Gist options
  • Save mcalavera81/fa4402e33eceae86680524d178e92b52 to your computer and use it in GitHub Desktop.
Save mcalavera81/fa4402e33eceae86680524d178e92b52 to your computer and use it in GitHub Desktop.
Reading YAML files
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