List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.facebook.api.FacebookPostActivitySerializer.java
private void addObjectId(Activity activity, JsonNode value) { activity.getObject().setId(getObjectId("facebook", activity.getObject().getObjectType(), value.asText())); }
From source file:net.paulgray.mocklti2.tools.LtiToolController.java
@Lti @RequestMapping(value = "/api/tool_proxy_registration", method = RequestMethod.POST) public ResponseEntity registerConsumerProfile(HttpServletRequest request, LtiVerificationResult result, @RequestBody ToolProxy toolProxy, @RequestParam Integer toolId) throws JsonProcessingException { if (!result.getSuccess()) { return new ResponseEntity(result.getError() + result.getMessage(), HttpStatus.BAD_REQUEST); } else {/*from w ww. j ava 2 s. c o m*/ LtiToolProxy ltiToolProxy = new LtiToolProxy(); //TODO: refactor this whole block... there needs to be a better way! ObjectMapper mapper = new ObjectMapper(); //find the base url for lti launch messages String defaultBaseUrl = ""; String secureBaseUrl = ""; if (toolProxy.getTool_profile().getBase_url_choice().isArray()) { for (JsonNode url_choice : toolProxy.getTool_profile().getBase_url_choice()) { System.out.println("Looking at choice's selector: " + url_choice.get("selector")); if (url_choice.get("selector") != null && url_choice.get("selector").get("applies_to") != null && url_choice.get("selector").get("applies_to").isArray()) { for (JsonNode url_application : url_choice.get("selector").get("applies_to")) { //Does 'MessageHandler' in this context refer to an *lti launch message* ? if (url_application.asText().equals("MessageHandler")) { defaultBaseUrl = url_choice.get("default_base_url").asText(); secureBaseUrl = url_choice.get("secure_base_url").asText(); } } } } } logger.info("Extracted base url: " + defaultBaseUrl); logger.info("Extracted secure base url: " + secureBaseUrl); //find the basic-lti-launch-request. //This part I'm unsure of. Why is there a "message" attribute on the tool_profile itself, as well as one each resource_handler definition? for (JsonNode resource_handler : toolProxy.getTool_profile().getResource_handler()) { if (resource_handler.get("message") != null && resource_handler.get("message").isArray()) { for (JsonNode message : resource_handler.get("message")) { if (message.get("message_type") != null && message.get("message_type").asText() .equals(ToolConsumer.LtiCapability.BASICLTI_LAUNCH)) { ltiToolProxy.setDefaultUrl(defaultBaseUrl + message.get("path").asText()); ltiToolProxy.setSecureUrl(secureBaseUrl + message.get("path").asText()); } } } } ltiToolProxy.setKey(toolProxy.getTool_proxy_guid()); ltiToolProxy.setSecret(toolProxy.getSecurity_contract().getShared_secret()); //change the tool's state to "registered" LtiTool ltiTool = ltiToolService.getToolForId(toolId); ltiTool.getToolProxies().add(ltiToolProxy); ltiTool.setState(LtiTool.State.registered); ltiToolProxy.setTool(ltiTool); ltiToolService.updateTool(ltiTool); return new ResponseEntity(HttpStatus.CREATED); } }
From source file:com.baasbox.commands.LinksResource.java
private String getDestId(JsonNode command) throws CommandParsingException { JsonNode node = command.get(ScriptCommand.PARAMS).get(DEST_ID); if (node == null || (!node.isTextual())) { throw new CommandParsingException(command, "missing destId"); }/*from ww w . j av a2 s.c o m*/ return node.asText(); }
From source file:com.baasbox.commands.LinksResource.java
private String getLinkName(JsonNode command) throws CommandParsingException { JsonNode node = command.get(ScriptCommand.PARAMS).get(LINK_NAME); if (node == null || (!node.isTextual())) { throw new CommandParsingException(command, "missing destId"); }//w w w.j av a 2 s . c o m return node.asText(); }
From source file:com.baasbox.commands.LinksResource.java
private String getSourceId(JsonNode command) throws CommandParsingException { JsonNode node = command.get(ScriptCommand.PARAMS).get(SOURCE_ID); if (node == null || (!node.isTextual())) { throw new CommandParsingException(command, "missing sourceId"); }/* w w w .ja v a 2s .com*/ return node.asText(); }
From source file:org.apache.streams.rss.provider.RssStreamProviderTask.java
/** * Reads the url and queues the data// w ww. j av a 2 s .c o m * @param feedUrl rss feed url * @return set of all article urls that were read from the feed * @throws IOException when it cannot connect to the url or the url is malformed * @throws FeedException when it cannot reed the feed. */ @VisibleForTesting protected Set<String> queueFeedEntries(URL feedUrl) throws IOException, FeedException { Set<String> batch = Sets.newConcurrentHashSet(); URLConnection connection = feedUrl.openConnection(); connection.setConnectTimeout(this.timeOut); connection.setConnectTimeout(this.timeOut); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new InputStreamReader(connection.getInputStream())); for (Object entryObj : feed.getEntries()) { SyndEntry entry = (SyndEntry) entryObj; ObjectNode nodeEntry = this.serializer.deserialize(entry); nodeEntry.put(RSS_KEY, this.rssFeed); String entryId = determineId(nodeEntry); batch.add(entryId); StreamsDatum datum = new StreamsDatum(nodeEntry); try { JsonNode published = nodeEntry.get(DATE_KEY); if (published != null) { try { DateTime date = RFC3339Utils.parseToUTC(published.asText()); if (date.isAfter(this.publishedSince) && (!this.perpetual || !seenBefore(entryId, this.rssFeed))) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } catch (Exception e) { LOGGER.trace( "Failed to parse date from object node, attempting to add node to queue by default."); if (!this.perpetual || !seenBefore(entryId, this.rssFeed)) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } } else { LOGGER.debug("No published date present, attempting to add node to queue by default."); if (!this.perpetual || !seenBefore(entryId, this.rssFeed)) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } } catch (InterruptedException ie) { LOGGER.error("Interupted Exception."); Thread.currentThread().interrupt(); } } return batch; }
From source file:com.spankingrpgs.scarletmoon.characters.CrimsonGameCharacter.java
@Override public void load(JsonNode characterObject) { setName(characterObject.get("name").asText().trim()); setGender(Gender.valueOf(characterObject.get("gender").asText().trim())); JsonNode descriptionNode = characterObject.get("rawDescription"); String description = descriptionNode.isNull() ? null : descriptionNode.asText().trim(); setDescription(description);//from w w w . ja v a 2s . c om setBattleName(characterObject.get("battleName").asText().trim()); loadPrintedNames(characterObject.get("bothPrintedNames")); loadAttackRanges(characterObject.get("attackRanges")); loadStatistics(characterObject.get("primaryStatistics")); loadEquipment(characterObject.get("equipmentNames")); loadAppearance(characterObject.get("appearance")); loadSkills(characterObject.get("skills")); loadStatistics(characterObject.get("secondaryStatistics")); }
From source file:com.amazonaws.samples.SamplesGenerator.java
private void getAssignmentValue(final StringBuilder sb, final JsonNode node, MemberModel memberModel) { if (memberModel.isSimple()) { sb.append(formatPrimitiveValue(memberModel.getSetterModel().getSimpleType(), node.asText())); } else if (memberModel.isList()) { ListModel listModel = memberModel.getListModel(); Iterator<JsonNode> iter = node.iterator(); while (iter.hasNext()) { JsonNode entry = iter.next(); if (listModel.getListMemberModel() == null) { sb.append(formatPrimitiveValue(listModel.getMemberType(), entry.asText())); } else { getAssignmentValue(sb, entry, listModel.getListMemberModel()); }//w w w.java 2s . c o m if (iter.hasNext()) { sb.append(", "); } } } else if (memberModel.isMap()) { MapModel mapModel = memberModel.getMapModel(); Iterator<Entry<String, JsonNode>> iter = node.fields(); while (iter.hasNext()) { Entry<String, JsonNode> field = iter.next(); JsonNode curNode = field.getValue(); sb.append(String.format(".add%sEntry(", firstCharToUpper(memberModel.getC2jName()))); sb.append(formatPrimitiveValue(mapModel.getKeyType(), field.getKey())); sb.append(", "); if (mapModel.getValueModel() == null) { sb.append(formatPrimitiveValue(mapModel.getValueType(), curNode.asText())); } else { getAssignmentValue(sb, curNode, mapModel.getValueModel()); } sb.append(")"); } } else { sb.append(String.format("new %s()", memberModel.getC2jShape())); Iterator<Entry<String, JsonNode>> iter = node.fields(); ShapeModel memberShape = model.getShapes().get(memberModel.getC2jShape()); while (iter.hasNext()) { Entry<String, JsonNode> field = iter.next(); MemberModel fieldMemberModel = memberShape.getMemberByC2jName(field.getKey()); if (fieldMemberModel.isMap()) { getAssignmentValue(sb, field.getValue(), fieldMemberModel); } else { sb.append(String.format(".with%s(", firstCharToUpper(field.getKey()))); getAssignmentValue(sb, field.getValue(), fieldMemberModel); sb.append(")"); } } } }
From source file:org.opendaylight.alto.core.northbound.route.costmap.impl.AltoNorthboundRouteCostmap.java
protected List<String> arrayNode2List(String field, ArrayNode node) { HashSet<String> retval = new HashSet<String>(); for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) { JsonNode data = itr.next(); retval.add(data.asText()); }// ww w . j a va 2 s.c o m return new LinkedList<String>(retval); }
From source file:org.jboss.aerogear.sync.diffmatchpatch.server.DiffMatchPatchServerSynchronizer.java
@Override public Document<String> documentFromJson(JsonNode json) { final JsonNode contentNode = json.get("content"); String content = null;//w w w. ja va 2 s.com if (contentNode != null && !contentNode.isNull()) { if (contentNode.isArray() || contentNode.isObject()) { content = JsonMapper.toString(contentNode); } else { content = contentNode.asText(); } } return new DefaultDocument<String>(json.get("id").asText(), content); }