Package com.typesafe.config

Examples of com.typesafe.config.ConfigValue.valueType()


        String classField = pluginMap.classField();
        ConfigValue typeValue = configObject.get(classField);
        if (typeValue != null) {
            if (typeValue.valueType() != ConfigValueType.STRING) {
                throw new ConfigException.WrongType(typeValue.origin(), classField,
                                                    "STRING", typeValue.valueType().toString());
            }
            String stype = (String) typeValue.unwrapped();
            try {
                Class<T> normalType = (Class<T>) pluginMap.getClass(stype);
                ConfigObject aliasDefaults = pluginMap.aliasDefaults(stype);
View Full Code Here


                try {
                    Class<T> singleKeyType = (Class<T>) pluginMap.getClass(singleKeyName);
                    CodableClassInfo singleKeyInfo = getOrCreateClassInfo(singleKeyType);
                    ConfigObject aliasDefaults = pluginMap.aliasDefaults(singleKeyName);
                    ConfigValue configValue = configObject.get(singleKeyName);
                    if (configValue.valueType() != ConfigValueType.OBJECT) {
                        if (aliasDefaults.get("_primary") != null) {
                            // if value is not an object, try supporting _primary syntax to derive one
                            configValue = configValue.atPath((String) aliasDefaults.get("_primary").unwrapped()).root();
                        } else if (ValueCodable.class.isAssignableFrom(singleKeyType)) {
                            // see if the resolved type is innately okay with non-objects
View Full Code Here

                                throw new ConfigException.BadValue(configValue.origin(), singleKeyType.getName(),
                                                                   "exception during instantiation of a ValueCodable", ex);
                            }
                        } else {
                            throw new ConfigException.WrongType(configValue.origin(), singleKeyName,
                                                                "OBJECT", configValue.valueType().toString());
                        }
                    }
                    ConfigObject fieldValues = ((ConfigObject) configValue).withFallback(aliasDefaults);
                    return createAndPopulate(singleKeyInfo, singleKeyType, fieldValues);
                } catch (ClassNotFoundException ignored) {
View Full Code Here

                                                 + config.origin().description());
        }
        CodableClassInfo typeInfo = codec.getOrCreateClassInfo(type);
        PluginMap pluginMap = typeInfo.getPluginMap();
        ConfigValue valueOrResolvedRoot = resolveType(type, config, pluginMap);
        if (valueOrResolvedRoot.valueType() != ConfigValueType.OBJECT) {
            return valueOrResolvedRoot;
        }
        ConfigObject root = (ConfigObject) valueOrResolvedRoot;
        String classField = pluginMap.classField();
        if (root.get(classField) != null) {
View Full Code Here

                                                " for " + pluginMap);
        }
        ConfigObject root = (ConfigObject) configValue;
        ConfigValue classValue = root.get(classField);
        // normal, explicit typing
        if ((classValue != null) && (classValue.valueType() == ConfigValueType.STRING)) {
            String classValueString = (String) classValue.unwrapped();
            ConfigObject aliasDefaults = pluginMap.aliasDefaults(classValueString);
            return root.withFallback(aliasDefaults);
        }
View Full Code Here

                String onlyKey = root.keySet().iterator().next();
                try {
                    pluginMap.getClass(onlyKey); // make sure key is a valid type
                    ConfigValue onlyKeyValue = root.values().iterator().next();
                    ConfigObject aliasDefaults = pluginMap.aliasDefaults(onlyKey);
                    if (onlyKeyValue.valueType() != ConfigValueType.OBJECT) {
                        if (aliasDefaults.get("_primary") != null) {
                            onlyKeyValue = onlyKeyValue.atPath((String) aliasDefaults.get("_primary").unwrapped()).root();
                        } else {
                            throw new ConfigException.WrongType(onlyKeyValue.origin(), onlyKey,
                                                                "OBJECT", onlyKeyValue.valueType().toString());
View Full Code Here

                    if (onlyKeyValue.valueType() != ConfigValueType.OBJECT) {
                        if (aliasDefaults.get("_primary") != null) {
                            onlyKeyValue = onlyKeyValue.atPath((String) aliasDefaults.get("_primary").unwrapped()).root();
                        } else {
                            throw new ConfigException.WrongType(onlyKeyValue.origin(), onlyKey,
                                                                "OBJECT", onlyKeyValue.valueType().toString());
                        }
                    }
                    ConfigObject fieldValues = (ConfigObject) onlyKeyValue;
                    return fieldValues.withValue(classField, ConfigValueFactory.fromAnyRef(
                            onlyKey, "single key to type from " + root.origin().description()))
View Full Code Here

        return _nodeCursor.currentNode();
    }

    protected JsonNode currentNumericNode() throws JsonParseException {
        ConfigValue configValue = currentNode();
        if ((configValue == null) || (configValue.valueType() != ConfigValueType.NUMBER)) {
            JsonToken t = (configValue == null) ? null : ConfigNodeCursor.forConfigValue(configValue);
            throw _constructError("Current token ("+t+") not numeric, can not use numeric value accessors");
        }
        Number value = (Number) configValue.unwrapped();
        if (value instanceof Double) {
View Full Code Here

     * contents of the current structured value (JSON array or object)
     */
    public final ConfigNodeCursor iterateChildren() {
        ConfigValue n = currentNode();
        if (n == null) throw new IllegalStateException("No current node");
        if (n.valueType() == LIST) { // false since we have already returned START_ARRAY
            return new Array((ConfigList) n, this);
        }
        if (n.valueType() == OBJECT) {
            return new Object((ConfigObject) n, this);
        }
View Full Code Here

        ConfigValue n = currentNode();
        if (n == null) throw new IllegalStateException("No current node");
        if (n.valueType() == LIST) { // false since we have already returned START_ARRAY
            return new Array((ConfigList) n, this);
        }
        if (n.valueType() == OBJECT) {
            return new Object((ConfigObject) n, this);
        }
        throw new IllegalStateException("Current node of type " + n.getClass().getName());
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.