List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static Integer convertToInteger(JsonNode node) throws Exception { if (node.isNumber()) { return node.asInt(); } else if (node.isTextual()) { return convertToInteger(node.asText()); } else if (node.isNull()) { return null; } else {//from w ww. ja va 2 s . c o m throw new Exception("Node: " + node + " cannot be converted to Integer"); } }
From source file:org.glowroot.tests.WebDriverIT.java
private static String getVersion(String content) throws IOException { JsonNode responseNode = new ObjectMapper().readTree(content); JsonNode versionNode = responseNode.get("version"); if (versionNode == null) { return responseNode.get("config").get("version").asText(); }//from w ww . ja va2 s . c o m return versionNode.asText(); }
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static Boolean convertToBoolean(JsonNode node) throws Exception { if (node.isBoolean()) { return node.asBoolean(); } else if (node.isTextual()) { return convertToBoolean(node.asText()); } else {/*from www. j a v a2 s. co m*/ throw new Exception("Node: " + node + " cannot be converted to Boolean"); } }
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static Short convertToShort(JsonNode node) throws Exception { if (node.isNumber()) { return (short) node.asInt(); } else if (node.isTextual()) { return convertToShort(node.asText()); } else if (node.isNull()) { return null; } else {/*from w w w . j a va 2s .co m*/ throw new Exception("Node: " + node + " cannot be converted to Short"); } }
From source file:com.helger.wsdlgen.exchange.InterfaceReader.java
@Nullable private static String _getChildAsText(@Nonnull final ObjectNode aNode, final String sFieldName) { final JsonNode aChildNode = aNode.get(sFieldName); if (aChildNode == null) return null; return _cleanupText(aChildNode.asText()); }
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static Float convertToFloat(JsonNode node) throws Exception { if (node.isNumber()) { return (float) node.asDouble(); } else if (node.isTextual()) { return convertToFloat(node.asText()); } else if (node.isNull()) { return null; } else {/*ww w. ja v a2 s . co m*/ throw new Exception("Node: " + node + " cannot be converted to Float"); } }
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static BigInteger convertToBigInteger(JsonNode node) throws Exception { if (node.isNumber()) { return node.bigIntegerValue(); } else if (node.isTextual()) { return convertToBigInteger(node.asText()); } else if (node.isNull()) { return null; } else {/*from w w w . ja v a 2 s . co m*/ throw new Exception("Node: " + node + " cannot be converted to BigInteger"); } }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
protected static InputStream getJsonPropertyValue(final InputStream src, final String name) throws Exception { ObjectMapper mapper = new ObjectMapper(); final JsonNode srcNode = mapper.readTree(src); JsonNode node = getJsonProperty(srcNode, new String[] { name }, 0); return IOUtils.toInputStream(node.asText()); }
From source file:org.dswarm.common.model.util.AttributePathUtil.java
public static AttributePath parseAttributePathNode(final JsonNode attributePathNode, final Map<String, Attribute> attributeMap, final Map<String, AttributePath> attributePathMap) { if (attributePathNode == null) { return null; }/* w w w .ja v a 2 s . c o m*/ final String attributePathString = attributePathNode.asText(); return parseAttributePathString(attributePathString, attributeMap, attributePathMap); }
From source file:io.apiman.gateway.test.junit.servlet.ServletGatewayTestServer.java
/** * Configures the gateway by settings system properties. *///from w w w . j a v a2 s .co m protected static void configureGateway(JsonNode config) { Map<String, String> props = new HashMap<>(); // Global settings - all tests share but can override props.put(GatewayConfigProperties.PLUGIN_REGISTRY_CLASS, DefaultPluginRegistry.class.getName()); props.put(GatewayConfigProperties.PLUGIN_REGISTRY_CLASS + ".pluginsDir", new File("target/plugintmp").getAbsolutePath()); props.put(GatewayConfigProperties.CONNECTOR_FACTORY_CLASS, HttpConnectorFactory.class.getName()); props.put(GatewayConfigProperties.POLICY_FACTORY_CLASS, PolicyFactoryImpl.class.getName()); props.put(GatewayConfigProperties.COMPONENT_PREFIX + IPolicyFailureFactoryComponent.class.getSimpleName(), PolicyFailureFactoryComponent.class.getName()); props.put(GatewayConfigProperties.COMPONENT_PREFIX + IHttpClientComponent.class.getSimpleName(), HttpClientComponentImpl.class.getName()); props.put(GatewayConfigProperties.COMPONENT_PREFIX + IBufferFactoryComponent.class.getSimpleName(), ByteBufferFactoryComponent.class.getName()); props.put(GatewayConfigProperties.METRICS_CLASS, TestMetrics.class.getName()); // First, process the config files. if (config.has("config-files")) { JsonNode configFilesNode = config.get("config-files"); for (JsonNode jsonNode : configFilesNode) { String configFile = jsonNode.asText(); Properties loadedProps = loadConfigFile(configFile); for (Entry<Object, Object> entry : loadedProps.entrySet()) { props.put(entry.getKey().toString(), entry.getValue().toString()); } } } // Then layer on top of that, the properties defined in the config itself. if (config.has("config-properties")) { JsonNode configNode = config.get("config-properties"); Iterator<String> fieldNames = configNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); String value = configNode.get(fieldName).asText(); props.put(fieldName, value); } } for (Entry<String, String> entry : props.entrySet()) { TestUtil.setProperty(entry.getKey(), entry.getValue()); } }