List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:org.numenta.nupic.algorithms.CLAClassifierDeserializer.java
@Override public CLAClassifier deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec();// w w w .jav a2s . c o m JsonNode node = oc.readTree(jp); CLAClassifier retVal = new CLAClassifier(); retVal.alpha = node.get("alpha").asDouble(); retVal.actValueAlpha = node.get("actValueAlpha").asDouble(); retVal.learnIteration = node.get("learnIteration").asInt(); retVal.recordNumMinusLearnIteration = node.get("recordNumMinusLearnIteration").asInt(); retVal.maxBucketIdx = node.get("maxBucketIdx").asInt(); String[] steps = node.get("steps").asText().split(","); TIntList t = new TIntArrayList(); for (String step : steps) { t.add(Integer.parseInt(step)); } retVal.steps = t; String[] tupleStrs = node.get("patternNZHistory").asText().split(";"); Deque<Tuple> patterns = new Deque<Tuple>(tupleStrs.length); for (String tupleStr : tupleStrs) { String[] tupleParts = tupleStr.split("-"); int iteration = Integer.parseInt(tupleParts[0]); String pattern = tupleParts[1].substring(1, tupleParts[1].indexOf("]")).trim(); String[] indexes = pattern.split(","); int[] indices = new int[indexes.length]; for (int i = 0; i < indices.length; i++) { indices[i] = Integer.parseInt(indexes[i].trim()); } Tuple tup = new Tuple(iteration, indices); patterns.append(tup); } retVal.patternNZHistory = patterns; Map<Tuple, BitHistory> bitHistoryMap = new HashMap<Tuple, BitHistory>(); String[] bithists = node.get("activeBitHistory").asText().split(";"); for (String bh : bithists) { String[] parts = bh.split("-"); String[] left = parts[0].split(","); Tuple iteration = new Tuple(Integer.parseInt(left[0].trim()), Integer.parseInt(left[1].trim())); BitHistory bitHistory = new BitHistory(); String[] right = parts[1].split("="); bitHistory.id = right[0].trim(); TDoubleList dubs = new TDoubleArrayList(); String[] stats = right[1].substring(1, right[1].indexOf("}")).trim().split(","); for (int i = 0; i < stats.length; i++) { dubs.add(Double.parseDouble(stats[i].trim())); } bitHistory.stats = dubs; bitHistory.lastTotalUpdate = Integer.parseInt(right[2].trim()); bitHistoryMap.put(iteration, bitHistory); } retVal.activeBitHistory = bitHistoryMap; ArrayNode jn = (ArrayNode) node.get("actualValues"); List<Object> l = new ArrayList<Object>(); for (int i = 0; i < jn.size(); i++) { JsonNode n = jn.get(i); try { double d = Double.parseDouble(n.asText().trim()); l.add(d); } catch (Exception e) { l.add(n.asText().trim()); } } retVal.actualValues = l; //Go back and set the classifier on the BitHistory objects for (Tuple tuple : bitHistoryMap.keySet()) { bitHistoryMap.get(tuple).classifier = retVal; } return retVal; }
From source file:com.arpnetworking.metrics.proxy.models.protocol.v2.LogMessagesProcessor.java
private void unsubscribe(final Path log, final ArrayNode regexes) { if (!_logsSubscriptions.containsKey(log)) { return;/*from ww w.j a v a 2 s . co m*/ } final Set<String> logsRegexes = _logsSubscriptions.get(log); for (JsonNode node : regexes) { logsRegexes.remove(node.asText()); } }
From source file:org.dswarm.graph.resources.GraphResource.java
protected Optional<String> getStringValue(final String key, final JsonNode json) { final JsonNode node = json.get(key); final Optional<String> optionalValue; if (node != null) { optionalValue = Optional.ofNullable(node.asText()); } else {//from w w w . j av a 2 s . c o m optionalValue = Optional.empty(); } return optionalValue; }
From source file:com.spotify.ffwd.json.JsonObjectMapperDecoder.java
private String decodeString(JsonNode tree, String name) { final JsonNode n = tree.get(name); if (n == null) return null; return n.asText(); }
From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java
private Collection<ReplaceableAttribute> getAttributesFrom(ArrayNode attributesNode, boolean replaceP) { List<ReplaceableAttribute> attributeList = new ArrayList<ReplaceableAttribute>(); for (int i = 0; i < attributesNode.size(); i++) { ObjectNode objectNode = (ObjectNode) attributesNode.get(i); Iterator<String> itFieldName = objectNode.fieldNames(); while (itFieldName.hasNext()) { String key = itFieldName.next(); JsonNode valueNode = objectNode.get(key); if (valueNode.isValueNode()) { attributeList.add(new ReplaceableAttribute(key, valueNode.asText(), replaceP)); } else if (valueNode.isArray()) { for (int j = 0; j < valueNode.size(); j++) { JsonNode scalarValueNode = valueNode.get(j); attributeList.add(new ReplaceableAttribute(key, scalarValueNode.asText(), replaceP)); }/*from w ww.j a v a 2 s . c o m*/ } } } return attributeList; }
From source file:com.arpnetworking.metrics.proxy.models.protocol.v2.LogMessagesProcessor.java
private void subscribe(final Path log, final ArrayNode regexes) { if (!_logsSubscriptions.containsKey(log)) { _logsSubscriptions.put(log, Sets.<String>newHashSet()); }// w ww. j ava 2 s . co m final Set<String> logsRegexes = _logsSubscriptions.get(log); for (JsonNode node : regexes) { final String regex = node.asText(); logsRegexes.add(regex); if (!PATTERNS_MAP.containsKey(regex)) { PATTERNS_MAP.put(regex, Pattern.compile(regex)); } } }
From source file:org.walkmod.conf.providers.yml.AbstractYMLConfigurationAction.java
@Override public void execute() throws Exception { JsonNode node = provider.getRootNode(); boolean isMultiModule = node.has("modules"); if (recursive && isMultiModule) { JsonNode aux = node.get("modules"); if (aux.isArray()) { ArrayNode modules = (ArrayNode) aux; int max = modules.size(); for (int i = 0; i < max; i++) { JsonNode module = modules.get(i); if (module.isTextual()) { String moduleDir = module.asText(); try { File auxFile = new File(provider.getFileName()).getCanonicalFile().getParentFile(); YAMLConfigurationProvider child = new YAMLConfigurationProvider( auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml"); child.createConfig(); AbstractYMLConfigurationAction childAction = clone(child, recursive); childAction.execute(); } catch (IOException e) { throw new TransformerException(e); }/*from ww w. ja v a2 s . c o m*/ } } } } else { doAction(node); } }
From source file:com.turn.shapeshifter.AutoSerializerTest.java
@Test public void testSerializeWithRepeatedPrimitive() throws Exception { Actor actor = Actor.newBuilder().setName("James Dean").addQuotes("Foo").build(); JsonNode result = new AutoSerializer(Actor.getDescriptor()).serialize(actor, ReadableSchemaRegistry.EMPTY); Assert.assertTrue(result.isObject()); Assert.assertEquals(JsonToken.VALUE_STRING, result.get("name").asToken()); Assert.assertEquals("James Dean", result.get("name").asText()); JsonNode array = result.get("quotes"); Assert.assertTrue(array.isArray());/* w ww . ja v a2s. com*/ Assert.assertEquals(1, array.size()); JsonNode quoteNode = array.get(0); Assert.assertEquals(JsonToken.VALUE_STRING, quoteNode.asToken()); Assert.assertEquals("Foo", quoteNode.asText()); }
From source file:com.monarchapis.driver.model.Claims.java
public Optional<String> getString(String... path) { JsonNode node = getPathNode(path); if (node.isTextual()) { return Optional.of(node.asText()); } else {//from ww w .ja v a2s . com return Optional.absent(); } }
From source file:io.syndesis.connector.catalog.ConnectorCatalog.java
private String extractJavaType(String json) { try {/*from w ww . jav a 2 s. co m*/ ObjectNode node = (ObjectNode) new ObjectMapper().readTree(json); JsonNode c = node.get("component"); if (c != null) { JsonNode ret = c.get("javaType"); if (ret != null) { return ret.asText(); } } return null; } catch (IOException e) { return null; } }