Example usage for com.fasterxml.jackson.databind JsonNode textValue

List of usage examples for com.fasterxml.jackson.databind JsonNode textValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode textValue.

Prototype

public String textValue() 

Source Link

Usage

From source file:org.n52.iceland.config.json.JsonSettingsDao.java

protected Object decodeValue(SettingType type, JsonNode node) {
    switch (type) {
    case INTEGER:
        if (!node.canConvertToInt()) {
            numberDecodeError(type, node);
        }//www .  j a  v  a2  s. c  o  m
        return node.intValue();
    case NUMERIC:
        if (!node.isDouble()) {
            numberDecodeError(type, node);
        }
        return node.doubleValue();
    case BOOLEAN:
        return node.booleanValue();
    case TIMEINSTANT:
        return this.settingValueFactory.parseTimeInstant(node.textValue());
    case FILE:
        return this.settingValueFactory.parseFile(node.textValue());
    case STRING:
        return node.textValue();
    case URI:
        return this.settingValueFactory.parseUri(node.textValue());
    case MULTILINGUAL_STRING:
        return decodeMultilingualString(node);
    case CHOICE:
        return node.textValue();
    default:
        throw new ConfigurationError(String.format("Unknown Type %s", type));
    }
}

From source file:com.liferay.sync.engine.SyncSystemTest.java

protected String getString(JsonNode jsonNode, String key, String defaultValue) {

    JsonNode childJsonNode = jsonNode.get(key);

    if (childJsonNode == null) {
        return defaultValue;
    }/*ww  w  .ja  v a 2s. c o  m*/

    FileSystem fileSystem = FileSystems.getDefault();

    String value = childJsonNode.textValue();

    return value.replace("/", fileSystem.getSeparator());
}

From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java

@Override
public ReportDTO deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    ReportTypeEnum reportTypeEnum = node.get(REPORT_TYPE) != null
            ? ReportTypeEnum.getReportTypeEnum(node.get(REPORT_TYPE).textValue())
            : ReportTypeEnum.STANDARD;//from   w ww. ja v a  2s.c om

    List<FilterDTO> filterDTOList = new ArrayList<>();

    JsonNode reportIdNode = node.get(ID);
    Long reportId = null;
    if (reportIdNode != null) {
        reportId = reportIdNode.longValue();
    }

    JsonNode filterNode = node.get(FILTER_EXPRESSION);

    if (filterNode != null) {
        addVmsFilters(filterNode.get("vms"), filterDTOList, reportId);
        addAssets(filterNode.get(ASSETS), filterDTOList, reportId);
        addArea(filterNode.get("areas"), filterDTOList, reportId);
        addCommon(filterNode.get("common"), filterDTOList, reportId);
        addFaFilters(filterNode.get("fa"), filterDTOList, reportId);
        if (ReportTypeEnum.SUMMARY.equals(reportTypeEnum)) {
            addGroupCriteria(filterNode.get("criteria"), filterDTOList, reportId, jsonParser);
        }
    }

    boolean withMap = false;
    JsonNode witMapNode = node.get(WITH_MAP);
    if (witMapNode != null) {
        withMap = witMapNode.booleanValue();
    }

    VisibilityEnum visibilityEnum = null;
    JsonNode visibilityNode = node.get(VISIBILITY);
    if (visibilityNode != null) {
        String s = visibilityNode.textValue();
        if (s != null) {
            visibilityEnum = VisibilityEnum.valueOf(s.toUpperCase());
        }
    }

    String nameValue = null;
    JsonNode nameNode = node.get(NAME);
    if (nameNode != null) {
        nameValue = nameNode.textValue();
    }

    JsonNode createdOnNode = node.get(CREATED_ON);
    String createdOnValue = null;
    if (createdOnNode != null) {
        createdOnValue = createdOnNode.textValue();
    }

    JsonNode editableNode = node.get("editable");
    boolean editableValue = false;
    if (createdOnNode != null) {
        editableValue = editableNode.booleanValue();
    }

    ReportDTO build = ReportDTO.builder()
            .description(node.get(DESC) != null ? node.get(DESC).textValue() : null)
            .id(node.get(ID) != null ? node.get(ID).longValue() : null).name(nameValue).withMap(withMap)
            .createdBy(node.get(CREATED_BY) != null ? node.get(CREATED_BY).textValue() : null)
            .filters(filterDTOList).visibility(visibilityEnum)
            .mapConfiguration(createMapConfigurationDTO(withMap, node.get(MAP_CONFIGURATION))).build();
    build.setReportTypeEnum(reportTypeEnum);
    build.setAudit(new AuditDTO(createdOnValue));
    build.setEditable(editableValue);
    return build;
}

From source file:org.apache.taverna.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.java

/**
 * Finds either local jar or artifact dependencies' URLs for the given classloader
 * sharing policy (passed inside configuration bean) and a workflowRunID (used to
 * retrieve the workflow) that will be added to this activity classloader's list of URLs.
 *//*  w ww. j  a  v a  2  s  . c o  m*/
private HashSet<URL> findDependencies(String dependencyType, JsonNode json, String workflowRunID) {
    ClassLoaderSharing classLoaderSharing;
    if (json.has("classLoaderSharing")) {
        classLoaderSharing = ClassLoaderSharing.fromString(json.get("classLoaderSharing").textValue());
    } else {
        classLoaderSharing = ClassLoaderSharing.workflow;
    }
    // Get the WorkflowInstanceFacade which contains the current workflow
    WeakReference<WorkflowInstanceFacade> wfFacadeRef = WorkflowInstanceFacade.workflowRunFacades
            .get(workflowRunID);
    WorkflowInstanceFacade wfFacade = null;
    if (wfFacadeRef != null) {
        wfFacade = wfFacadeRef.get();
    }
    Dataflow wf = null;
    if (wfFacade != null) {
        wf = wfFacade.getDataflow();
    }

    // Files of dependencies for all activities in the workflow that share the classloading policy
    HashSet<File> dependencies = new HashSet<File>();
    // Urls of all dependencies
    HashSet<URL> dependenciesURLs = new HashSet<URL>();

    if (wf != null) {
        // Merge in dependencies from all activities that have the same classloader-sharing
        // as this activity
        for (Processor proc : wf.getProcessors()) {
            // Nested workflow case
            if (!proc.getActivityList().isEmpty() && proc.getActivityList().get(0) instanceof NestedDataflow) {
                // Get the nested workflow
                Dataflow nestedWorkflow = ((NestedDataflow) proc.getActivityList().get(0)).getNestedDataflow();
                dependenciesURLs.addAll(findNestedDependencies(dependencyType, json, nestedWorkflow));
            } else { // Not nested - go through all of the processor's activities
                Activity<?> activity = proc.getActivityList().get(0);
                if (activity instanceof AbstractAsynchronousDependencyActivity) {
                    AbstractAsynchronousDependencyActivity dependencyActivity = (AbstractAsynchronousDependencyActivity) activity;
                    //                     if (dependencyType.equals(LOCAL_JARS)){
                    // Collect the files of all found local dependencies
                    if (dependencyActivity.getConfiguration().has("localDependency")) {
                        for (JsonNode jar : dependencyActivity.getConfiguration().get("localDependency")) {
                            try {
                                dependencies.add(new File(libDir, jar.textValue()));
                            } catch (Exception ex) {
                                logger.warn("Invalid URL for " + jar, ex);
                                continue;
                            }
                        }
                    }
                    //                     } else if (dependencyType.equals(ARTIFACTS) && this.getClass().getClassLoader() instanceof LocalArtifactClassLoader){
                    //                        LocalArtifactClassLoader cl = (LocalArtifactClassLoader) this.getClass().getClassLoader(); // this class is always loaded with LocalArtifactClassLoader
                    //                        // Get the LocalReposotpry capable of finding artifact jar files
                    //                        LocalRepository rep  = (LocalRepository) cl.getRepository();
                    //                        for (BasicArtifact art : ((DependencyActivityConfigurationBean) activity
                    //                                    .getConfiguration())
                    //                                    .getArtifactDependencies()){
                    //                           dependencies.add(rep.jarFile(art));
                    //                        }
                    //                     }
                }
            }
        }
    } else { // Just add dependencies for this activity since we can't get hold of the whole workflow
        //         if (dependencyType.equals(LOCAL_JARS)){
        if (json.has("localDependency")) {
            for (JsonNode jar : json.get("localDependency")) {
                try {
                    dependencies.add(new File(libDir, jar.textValue()));
                } catch (Exception ex) {
                    logger.warn("Invalid URL for " + jar, ex);
                    continue;
                }
            }
        }
        //         }
        //         else if (dependencyType.equals(ARTIFACTS)){
        //            if (this.getClass().getClassLoader() instanceof LocalArtifactClassLoader){ // This should normally be the case
        //               LocalArtifactClassLoader cl = (LocalArtifactClassLoader)this.getClass().getClassLoader();
        //               LocalRepository rep  = (LocalRepository)cl.getRepository();
        //               if (rep != null){
        //                  for (BasicArtifact art : configurationBean.getArtifactDependencies()){
        //                     dependencies.add(rep.jarFile(art));
        //                  }
        //               }
        //            }
        //            else{
        //               // Tests will not be loaded using the LocalArtifactClassLoader as athey are loaded
        //               // outside Raven so there is nothing we can do about this - some tests
        //               // with dependencies will probably fail
        //            }
        //         }
    }

    // Collect the URLs of all found dependencies
    for (File file : dependencies) {
        try {
            dependenciesURLs.add(file.toURI().toURL());
        } catch (Exception ex) {
            logger.warn("Invalid URL for " + file.getAbsolutePath(), ex);
            continue;
        }
    }
    return dependenciesURLs;
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void putString() {
    ObjectNode parent = new ObjectNode(factory);
    String name = "foo";
    String value = "bar";

    parser.putString(parent, name, value);

    JsonNode x = parent.get(name);//from  www.  j ava 2 s .  c  o  m

    Assert.assertNotNull(x);
    Assert.assertEquals(value, x.textValue());
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void putValueString() {
    ObjectNode parent = new ObjectNode(factory);
    String name = "foo";
    String value = "bar";

    parser.putValue(parent, name, value);

    JsonNode x = parent.get(name);//ww  w  .  j a v  a  2  s  .  co m

    Assert.assertNotNull(x);
    Assert.assertEquals(value, x.textValue());
}

From source file:com.github.fge.jsonschema.keyword.digest.draftv3.DraftV3DependenciesDigester.java

@Override
public JsonNode digest(final JsonNode schema) {
    final ObjectNode ret = FACTORY.objectNode();

    final ObjectNode propertyDeps = FACTORY.objectNode();
    ret.put("propertyDeps", propertyDeps);

    final ArrayNode schemaDeps = FACTORY.arrayNode();
    ret.put("schemaDeps", schemaDeps);

    final List<String> list = Lists.newArrayList();

    final Map<String, JsonNode> map = JacksonUtils.asMap(schema.get(keyword));

    String key;/*from  w w w .  ja  v  a  2s .co  m*/
    JsonNode value;
    NodeType type;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        key = entry.getKey();
        value = entry.getValue();
        type = NodeType.getNodeType(value);
        switch (type) {
        case OBJECT:
            list.add(key);
            break;
        case ARRAY:
            final JsonNode node = sortedSet(value);
            if (node.size() != 0)
                propertyDeps.put(key, node);
            break;
        case STRING:
            propertyDeps.put(key, FACTORY.arrayNode().add(value.textValue()));
        }
    }

    for (final String s : Ordering.natural().sortedCopy(list))
        schemaDeps.add(s);

    return ret;
}

From source file:org.graylog.plugins.pipelineprocessor.functions.json.SelectJsonPath.java

private Object unwrapJsonNode(Object value) {
    if (!(value instanceof JsonNode)) {
        return value;
    }//  w  w w  .j  a va2  s  .  c o m
    JsonNode read = ((JsonNode) value);
    switch (read.getNodeType()) {
    case ARRAY:
        return ImmutableList.copyOf(read.elements());
    case BINARY:
        try {
            return read.binaryValue();
        } catch (IOException e) {
            return null;
        }
    case BOOLEAN:
        return read.booleanValue();
    case MISSING:
    case NULL:
        return null;
    case NUMBER:
        return read.numberValue();
    case OBJECT:
        return read;
    case POJO:
        return read;
    case STRING:
        return read.textValue();
    }
    return read;
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void getObjectProperty() {
    String name = "name";
    String value = "value";
    ObjectNode parent = new ObjectNode(factory);
    parent.put(name, value);/*from   w  ww  . ja  va2s.c o m*/
    parent.put(name + "1", value + "1");

    JsonNode object = parser.getObjectProperty(parent, name);

    Assert.assertNotNull("couldn't find node by name", object);
    Assert.assertEquals(value, object.textValue());
}

From source file:org.springframework.cloud.stream.app.jdbc.sink.JdbcSinkConfiguration.java

@Bean
@ServiceActivator(autoStartup = "false", inputChannel = Sink.INPUT)
public JdbcMessageHandler jdbcMessageHandler(DataSource dataSource) {
    final MultiValueMap<String, Expression> columnExpressionVariations = new LinkedMultiValueMap<>();
    for (Map.Entry<String, String> entry : properties.getColumns().entrySet()) {
        String value = entry.getValue();
        columnExpressionVariations.add(entry.getKey(), spelExpressionParser.parseExpression(value));
        if (!value.startsWith("payload")) {
            columnExpressionVariations.add(entry.getKey(),
                    spelExpressionParser.parseExpression("payload." + value));
        }/*from  w  w w. ja v  a2  s  .c  o  m*/
    }
    JdbcMessageHandler jdbcMessageHandler = new JdbcMessageHandler(dataSource,
            generateSql(properties.getTableName(), columnExpressionVariations.keySet()));
    jdbcMessageHandler.setSqlParameterSourceFactory(new SqlParameterSourceFactory() {
        @Override
        public SqlParameterSource createParameterSource(Object o) {
            if (!(o instanceof Message)) {
                throw new IllegalArgumentException("Unable to handle type " + o.getClass().getName());
            }
            Message<?> message = (Message<?>) o;
            MapSqlParameterSource parameterSource = new MapSqlParameterSource();
            for (String key : columnExpressionVariations.keySet()) {
                List<Expression> spels = columnExpressionVariations.get(key);
                Object value = NOT_SET;
                EvaluationException lastException = null;
                for (Expression spel : spels) {
                    try {
                        value = spel.getValue(evaluationContext, message);
                        break;
                    } catch (EvaluationException e) {
                        lastException = e;
                    }
                }
                if (value == NOT_SET) {
                    if (lastException != null) {
                        logger.info(
                                "Could not find value for column '" + key + "': " + lastException.getMessage());
                    }
                    parameterSource.addValue(key, null);
                } else {
                    if (value instanceof JsonPropertyAccessor.ToStringFriendlyJsonNode) {
                        // Need to do some reflection until we have a getter for the Node
                        DirectFieldAccessor dfa = new DirectFieldAccessor(value);
                        JsonNode node = (JsonNode) dfa.getPropertyValue("node");
                        Object valueToUse;
                        if (node == null || node.isNull()) {
                            valueToUse = null;
                        } else if (node.isNumber()) {
                            valueToUse = node.numberValue();
                        } else if (node.isBoolean()) {
                            valueToUse = node.booleanValue();
                        } else {
                            valueToUse = node.textValue();
                        }
                        parameterSource.addValue(key, valueToUse);
                    } else {
                        parameterSource.addValue(key, value);
                    }
                }
            }
            return parameterSource;
        }
    });
    return jdbcMessageHandler;
}