List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:com.rusticisoftware.tincan.Agent.java
protected Agent(JsonNode jsonNode) { this();// w w w .j a v a2 s . c o m JsonNode nameNode = jsonNode.path("name"); if (!nameNode.isMissingNode()) { this.setName(nameNode.textValue()); } JsonNode mboxNode = jsonNode.path("mbox"); if (!mboxNode.isMissingNode()) { this.setMbox(mboxNode.textValue()); } JsonNode mboxSHA1SumNode = jsonNode.path("mbox_sha1sum"); if (!mboxSHA1SumNode.isMissingNode()) { this.setMboxSHA1Sum(mboxSHA1SumNode.textValue()); } JsonNode openIDNode = jsonNode.path("openid"); if (!openIDNode.isMissingNode()) { this.setOpenID(openIDNode.textValue()); } JsonNode acctNode = jsonNode.path("account"); if (!acctNode.isMissingNode()) { this.setAccount(new AgentAccount(acctNode)); } }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv4.DraftV4TypeSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); if (node.isTextual()) { final String s = node.textValue(); if (NodeType.fromName(s) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") .putArgument("found", s).putArgument("valid", ALL_TYPES)); return;// ww w . j a v a 2s . c o m } final int size = node.size(); if (size == 0) { report.error(newMsg(tree, bundle, "common.array.empty")); return; } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueElements = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type != NodeType.STRING) { report.error(newMsg(tree, bundle, "common.array.element.incorrectType").putArgument("index", index) .putArgument("expected", NodeType.STRING).putArgument("found", type)); continue; } final String found = element.textValue(); if (NodeType.fromName(found) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown").put("index", index) .putArgument("found", found).putArgument("valid", ALL_TYPES)); } if (!uniqueElements) report.error(newMsg(tree, bundle, "common.array.duplicateElements")); }
From source file:com.github.fge.jsonschema.syntax.checkers.helpers.DraftV3TypeKeywordSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isTextual()) { if (!typeIsValid(node.textValue())) report.error(newMsg(tree, "incorrectPrimitiveType").put("valid", EnumSet.allOf(NodeType.class)) .put("found", node)); return;// www . j av a 2 s . c o m } final int size = node.size(); final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueItems = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueItems = set.add(EQUIVALENCE.wrap(element)); if (type == OBJECT) { pointers.add(JsonPointer.of(keyword, index)); continue; } if (type != STRING) { report.error(newMsg(tree, "incorrectElementType").put("index", index) .put("expected", EnumSet.of(OBJECT, STRING)).put("found", type)); continue; } if (!typeIsValid(element.textValue())) report.error(newMsg(tree, "incorrectPrimitiveType").put("index", index) .put("valid", EnumSet.allOf(NodeType.class)).put("found", element)); } if (!uniqueItems) report.error(newMsg(tree, "elementsNotUnique")); }
From source file:com.vaporwarecorp.mirror.feature.AbstractCommand.java
protected String textValue(JsonNode node, String key) { JsonNode keyNode = jsonNodeValue(node, key); if (keyNode != null) { return StringUtils.trimToNull(keyNode.textValue()); }/*from w w w . j ava 2 s . c om*/ return null; }
From source file:eu.eubrazilcc.lvl.oauth2.rest.jackson.LinkedInMapper.java
public Optional<String> readOptionalValue(final String name) { checkArgument(isNotBlank(name), "Uninitialized or invalid name"); String value = null;/*from www.j ava 2 s . com*/ final JsonNode node = rootNode.path(name); if (!node.isMissingNode()) { value = trimToEmpty(node.textValue()); } return fromNullable(value); }
From source file:com.googlecode.batchfb.impl.GraphNodeExtractor.java
License:asdf
/** */ @Override/*from w w w . j a v a 2s.co m*/ protected JsonNode convert(JsonNode data) { if (!(data instanceof ArrayNode)) throw new IllegalStateException("Expected array node: " + data); JsonNode batchPart = ((ArrayNode) data).get(this.index); if (batchPart == null || batchPart.isNull()) throw new BrokenFacebookException( "Facebook returned an invalid batch response. There should not be a null at index " + index + " of this array: " + data); // This should be something like: // { // "code": 200, // "headers": [ { "name":"Content-Type", "value":"text/javascript; charset=UTF-8" } ], // "body":"{\"id\":\"asdf\"}" // }, JsonNode body = batchPart.get("body"); if (body == null || body.isNull()) return null; else return JSONUtils.toNode(body.textValue(), mapper); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3TypeKeywordSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isTextual()) { final String found = node.textValue(); if (!typeIsValid(found)) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") .putArgument("found", found).putArgument("valid", EnumSet.allOf(NodeType.class))); return;/* w w w . j a va 2 s. com*/ } final int size = node.size(); final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueItems = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueItems = set.add(EQUIVALENCE.wrap(element)); if (type == OBJECT) { pointers.add(JsonPointer.of(keyword, index)); continue; } if (type != STRING) { report.error(newMsg(tree, bundle, "common.array.element.incorrectType").putArgument("index", index) .putArgument("expected", EnumSet.of(OBJECT, STRING)).putArgument("found", type)); continue; } if (!typeIsValid(element.textValue())) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown").put("index", index) .putArgument("found", element.textValue()) .putArgument("valid", EnumSet.allOf(NodeType.class))); } if (!uniqueItems) report.error(newMsg(tree, bundle, "common.array.duplicateElements")); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.SyntaxProcessorTest.java
@Test public void unknownKeywordsAreReportedAsWarnings() throws ProcessingException { final ObjectNode node = FACTORY.objectNode(); node.put("foo", ""); node.put("bar", ""); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), node); final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree); final ArrayNode ignored = FACTORY.arrayNode(); // They appear in alphabetical order in the report! ignored.add("bar"); ignored.add("foo"); final Iterable<String> iterable = Iterables.transform(ignored, new Function<JsonNode, String>() { @Override//from w ww. j a va 2 s. c om public String apply(final JsonNode input) { return input.textValue(); } }); final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class); processor.process(report, holder); verify(report).log(same(LogLevel.WARNING), captor.capture()); final ProcessingMessage message = captor.getValue(); assertMessage(message).hasField("ignored", ignored) .hasMessage(BUNDLE.printf("core.unknownKeywords", iterable)); }
From source file:net.sf.taverna.t2.activities.apiconsumer.ApiConsumerActivityHealthChecker.java
public VisitReport visit(ApiConsumerActivity subject, List<Object> ancestors) { // Check if we can find the jar containing the apiconsumer's class Processor p = (Processor) VisitReport.findAncestor(ancestors, Processor.class); if (p == null) { return null; }/* w w w. java 2 s. co m*/ List<VisitReport> reports = new ArrayList<VisitReport>(); JsonNode configuration = subject.getConfiguration(); /* String className = configuration.getClassName(); try { // Try to load the API consumer's class ClassLoader classLoader = subject.getClassLoader(); classLoader.loadClass(className); reports.add(new VisitReport(HealthCheck.getInstance(), p, "Class found", HealthCheck.NO_PROBLEM, Status.OK)); // All is fine } catch (ClassNotFoundException e) { VisitReport vr = new VisitReport(HealthCheck.getInstance(), p, "Class missing", HealthCheck.MISSING_CLASS, Status.SEVERE); vr.setProperty("className", className); reports.add(vr); } */ // Check if we can find all the API consumer's dependencies LinkedHashSet<String> localDependencies = new LinkedHashSet<>(); for (JsonNode localDependency : configuration.get("localDependency")) { localDependencies.add(localDependency.textValue()); } if (!localDependencies.isEmpty()) { String[] jarArray = subject.libDir.list(new FileExtFilter(".jar")); if (jarArray != null) { List<String> jarFiles = Arrays.asList(jarArray); // URLs of all jars found in the lib directory for (String jar : localDependencies) { if (jarFiles.contains(jar)) { localDependencies.remove(jar); } } if (localDependencies.isEmpty()) { // all dependencies found reports.add(new VisitReport(HealthCheck.getInstance(), p, "Dependencies found", HealthCheck.NO_PROBLEM, Status.OK)); } else { VisitReport vr = new VisitReport(HealthCheck.getInstance(), p, "Dependencies missing", HealthCheck.MISSING_DEPENDENCY, Status.SEVERE); vr.setProperty("dependencies", localDependencies); vr.setProperty("directory", subject.libDir); reports.add(vr); } } } Status status = VisitReport.getWorstStatus(reports); VisitReport report = new VisitReport(HealthCheck.getInstance(), p, "API Consumer report", HealthCheck.NO_PROBLEM, status, reports); return report; }
From source file:com.rusticisoftware.tincan.Statement.java
public Statement(JsonNode jsonNode) throws URISyntaxException, MalformedURLException { super(jsonNode); JsonNode idNode = jsonNode.path("id"); if (!idNode.isMissingNode()) { this.setId(UUID.fromString(idNode.textValue())); }/*from w ww . j a v a 2s . c om*/ JsonNode storedNode = jsonNode.path("stored"); if (!storedNode.isMissingNode()) { this.setStored(new DateTime(storedNode.textValue())); } JsonNode authorityNode = jsonNode.path("authority"); if (!authorityNode.isMissingNode()) { this.setAuthority(Agent.fromJson(authorityNode)); } JsonNode voidedNode = jsonNode.path("voided"); if (!voidedNode.isMissingNode()) { this.setVoided(voidedNode.asBoolean()); } JsonNode versionNode = jsonNode.path("version"); if (!versionNode.isMissingNode()) { this.setVersion(TCAPIVersion.fromString(versionNode.textValue())); } }