List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:controllers.api.v1.Dataset.java
public static Result assignCommentToColumn(int datasetId, int columnId) { ObjectNode json = Json.newObject();/*from w w w.j a va2s . c o m*/ ArrayNode res = json.arrayNode(); JsonNode req = request().body().asJson(); if (req == null) { return badRequest("Expecting JSON data"); } if (req.isArray()) { for (int i = 0; i < req.size(); i++) { JsonNode obj = req.get(i); Boolean isSuccess = DatasetsDAO.assignColumnComment(obj.get("datasetId").asInt(), obj.get("columnId").asInt(), obj.get("commentId").asInt()); ObjectNode itemResponse = Json.newObject(); if (isSuccess) { itemResponse.put("success", "true"); } else { itemResponse.put("error", "true"); itemResponse.put("datasetId", datasetId); itemResponse.put("columnId", columnId); itemResponse.set("commentId", obj.get("comment_id")); } res.add(itemResponse); } } else { Boolean isSuccess = DatasetsDAO.assignColumnComment(datasetId, columnId, req.get("commentId").asInt()); ObjectNode itemResponse = Json.newObject(); if (isSuccess) { itemResponse.put("success", "true"); } else { itemResponse.put("error", "true"); itemResponse.put("datasetId", datasetId); itemResponse.put("columnId", columnId); itemResponse.set("commentId", req.get("commentId")); } res.add(itemResponse); } ObjectNode result = Json.newObject(); result.putArray("results").addAll(res); return ok(result); }
From source file:models.service.reminder.RemindService.java
/** * ????/*from ww w . ja v a 2 s. c o m*/ * * @param cfg json * @param items ??item * * @return true:, false: */ public static boolean verifyCfg(JsonNode cfg, Item[] items) { if (null == cfg) { return false; } boolean isSuccess = true; int count = 0; for (Item item : items) { if (!item.isEnable) { continue; } String itemVal = item.getVal(); // ?? if (cfg.hasNonNull(itemVal) && cfg.get(itemVal).isArray()) { JsonNode optionsNode = cfg.get(itemVal); Iterator<JsonNode> optionsIt = optionsNode.elements(); // ?? Set<String> optionSet = new HashSet<>(); while (optionsIt.hasNext()) { String optionString = optionsIt.next().asText(); if (!Option.isContainVal(optionString)) { isSuccess = false; break; } optionSet.add(optionString); } if (!isSuccess) { break; } // ????? if (optionSet.size() != optionsNode.size()) { isSuccess = false; break; } count++; } else { isSuccess = false; break; } } // ? if (cfg.size() > count) { isSuccess = false; } return isSuccess; }
From source file:org.eel.kitchen.jsonschema.keyword.MaxItemsKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { if (instance.size() <= intValue) return;//w ww. j a v a 2 s . c o m final Message.Builder msg = newMsg().addInfo(keyword, intValue).addInfo("found", instance.size()) .setMessage("too many elements in array"); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.keyword.MinItemsKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { if (instance.size() >= intValue) return;// w w w . j a v a2 s. c o m final Message.Builder msg = newMsg().addInfo(keyword, intValue).addInfo("found", instance.size()) .setMessage("not enough elements in array"); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.keyword.MaxPropertiesKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { if (instance.size() <= intValue) return;/*from w ww .j ava2s. c o m*/ final Message.Builder msg = newMsg().addInfo(keyword, intValue).addInfo("found", instance.size()) .setMessage("too many members in object"); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.keyword.MinPropertiesKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { if (instance.size() >= intValue) return;/* ww w . j a v a 2 s . c o m*/ final Message.Builder msg = newMsg().addInfo(keyword, intValue).addInfo("found", instance.size()) .setMessage("not enough members in object"); report.addMessage(msg.build()); }
From source file:capital.scalable.restdocs.response.ArrayLimitingJsonContentModifier.java
private JsonNodeConsumer shortenArray(final int maxElements) { return new JsonNodeConsumer() { @Override/*from www . ja v a 2 s . c om*/ public void accept(JsonNode node) { final int originalSize = node.size(); for (int i = maxElements; i < originalSize; i++) { ((ArrayNode) node).remove(maxElements); } } }; }
From source file:com.github.fge.jsonschema.syntax.checkers.draftv4.DraftV4ItemsSyntaxChecker.java
@Override protected void extraChecks(final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); if (node.isArray() && node.size() == 0) report.error(newMsg(tree, "emptyArray")); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv4.DraftV4ItemsSyntaxChecker.java
@Override protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); if (node.isArray() && node.size() == 0) report.error(newMsg(tree, bundle, "common.array.empty")); }
From source file:com.blacklocus.jres.response.bulk.JresBulkReply.java
public Iterable<JresBulkItemResult> getResults() { return Iterables.transform(node().get("items"), new Function<JsonNode, JresBulkItemResult>() { @Override//from w w w.java 2 s.com public JresBulkItemResult apply(JsonNode resultEntry) { assert resultEntry.size() == 1; Map.Entry<String, JsonNode> result = resultEntry.fields().next(); Item item = ObjectMappers.fromJson(result.getValue(), Item.class); return new JresBulkItemResult(result.getKey(), item); } }); }