Search in sources :

Example 1 with HoconTreeTraversingParser

use of com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser in project oap by oaplatform.

the class HoconFactoryWithFallback method _createParser.

@Override
protected HoconTreeTraversingParser _createParser(Reader r, IOContext ctxt) throws IOException {
    ConfigParseOptions options = ConfigParseOptions.defaults();
    Config config = ConfigFactory.parseReader(r, options);
    final Config unresolvedConfig = additinal.withFallback(config).withFallback(ConfigFactory.systemProperties());
    try {
        Config resolvedConfig = unresolvedConfig.resolve();
        return new HoconTreeTraversingParser(resolvedConfig.root(), _objectCodec);
    } catch (ConfigException e) {
        log.error(unresolvedConfig.root().render());
        throw e;
    }
}
Also used : HoconTreeTraversingParser(com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException) ConfigParseOptions(com.typesafe.config.ConfigParseOptions)

Example 2 with HoconTreeTraversingParser

use of com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser in project divolte-collector by divolte.

the class ValidatedConfiguration method mapped.

private static DivolteConfiguration mapped(final Config input) throws IOException {
    final Config resolved = input.resolve();
    final ObjectMapper mapper = new ObjectMapper();
    // snake_casing
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    // Ignore unknown stuff in the config
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    // Deserialization for Duration
    final SimpleModule module = new SimpleModule("Configuration Deserializers");
    module.addDeserializer(Duration.class, new DurationDeserializer());
    module.addDeserializer(Properties.class, new PropertiesDeserializer());
    mapper.registerModules(// JDK8 types (Optional, etc.)
    new Jdk8Module(), // Guava types (immutable collections)
    new GuavaModule(), // Support JDK8 parameter name discovery
    new ParameterNamesModule(), // Register custom deserializers module
    module);
    return mapper.readValue(new HoconTreeTraversingParser(resolved.root()), DivolteConfiguration.class);
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) HoconTreeTraversingParser(com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser) Config(com.typesafe.config.Config) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 3 with HoconTreeTraversingParser

use of com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser in project oap by oaplatform.

the class HoconFactoryWithSystemProperties method _createParser.

@Override
protected HoconTreeTraversingParser _createParser(Reader r, IOContext ctxt) throws IOException {
    var options = ConfigParseOptions.defaults();
    var config = ConfigFactory.parseReader(r, options);
    var unresolvedConfig = config.withFallback(ConfigFactory.systemProperties());
    // log.trace( unresolvedConfig.root().render() );
    try {
        final Config resolvedConfig = unresolvedConfig.resolve();
        return new HoconTreeTraversingParser(resolvedConfig.root(), _objectCodec);
    } catch (ConfigException e) {
        log.error(unresolvedConfig.root().render());
        throw e;
    }
}
Also used : HoconTreeTraversingParser(com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException)

Aggregations

HoconTreeTraversingParser (com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser)3 Config (com.typesafe.config.Config)3 ConfigException (com.typesafe.config.ConfigException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)1 ConfigParseOptions (com.typesafe.config.ConfigParseOptions)1