List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:io.swagger.parser.SwaggerCompatConverter.java
public Property propertyFromTypedObject(ExtendedTypedObject obj) { String type = obj.getType() == null ? null : obj.getType().toString(); String format = obj.getFormat() == null ? null : obj.getFormat().toString(); Property output = null;/*from w w w . j a v a2 s . c om*/ if ("array".equals(type)) { ArrayProperty am = new ArrayProperty(); Items items = obj.getItems(); if (items == null) { LOGGER.error("Error! Missing array type for property! Assuming `object` -- please fix your spec"); items = new Items(); items.setType("object"); } type = items.getType() == null ? null : items.getType().toString(); format = items.getFormat() == null ? null : items.getFormat().toString(); Map<PropertyBuilder.PropertyId, Object> args = new HashMap<>(); if (items.getExtraFields().get("enum") != null && items.getExtraFields().get("enum").isArray()) { ArrayNode an = (ArrayNode) items.getExtraFields().get("enum"); List<String> enumValues = new ArrayList<>(); for (JsonNode jn : an) { enumValues.add(jn.textValue()); } args.put(PropertyBuilder.PropertyId.ENUM, enumValues); } Property innerType = PropertyBuilder.build(type, format, args); if (innerType != null && !(innerType instanceof UntypedProperty)) { am.setItems(innerType); } else if (items.getRef() != null) { am.setItems(new RefProperty(items.getRef(), RefFormat.INTERNAL)); } else { am.setItems(new RefProperty(type, RefFormat.INTERNAL)); } output = am; } else { Map<PropertyBuilder.PropertyId, Object> args = new HashMap<PropertyBuilder.PropertyId, Object>(); if (obj.getEnumValues() != null && obj.getEnumValues().size() > 0) { args.put(PropertyBuilder.PropertyId.ENUM, obj.getEnumValues()); } if (obj.getMinimum() != null) { args.put(PropertyBuilder.PropertyId.MINIMUM, new BigDecimal(obj.getMinimum())); } if (obj.getMaximum() != null) { args.put(PropertyBuilder.PropertyId.MAXIMUM, new BigDecimal(obj.getMaximum())); } Property i = PropertyBuilder.build(type, format, args); if (i != null && !(i instanceof UntypedProperty)) { output = i; } else { if (obj.getRef() != null) { output = new RefProperty(obj.getRef(), RefFormat.INTERNAL); } else if (type != null && !type.equals("void")) { output = new RefProperty(type, RefFormat.INTERNAL); } } } return output; }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void handleLast(JsonNode common, List<FilterDTO> filterDTOList, Long reportId, String selectorNode, Selector positionSelector) { String startDateLast = null;/*from ww w .j av a 2 s .com*/ String endDateLast = null; if (common.get(START_DATE) != null) { startDateLast = common.get(START_DATE).asText(); } if (common.get(END_DATE) != null) { endDateLast = common.get(END_DATE).asText(); } Float value = common.get(PositionSelectorDTO.X_VALUE).floatValue(); CommonFilterDTO dto = CommonFilterDTO.CommonFilterDTOBuilder() .id(common.get(FilterDTO.ID) != null ? common.get(FilterDTO.ID).longValue() : null) .reportId(reportId) .startDate(startDateLast != null ? UI_FORMATTER.parseDateTime(startDateLast).toDate() : null) .endDate(endDateLast != null ? UI_FORMATTER.parseDateTime(endDateLast).toDate() : null).build(); filterDTOList.add(dto); JsonNode selectorType = common.get(PositionSelectorDTO.POSITION_TYPE_SELECTOR); if (selectorNode != null) { dto.setPositionSelector(PositionSelectorDTO.PositionSelectorDTOBuilder().value(value) .position(Position.valueOf(selectorType.textValue())).selector(positionSelector).build()); } }
From source file:org.activiti.rest.common.api.SecuredResource.java
protected Map<String, Object> retrieveVariables(JsonNode jsonNode) { Map<String, Object> variables = new HashMap<String, Object>(); if (jsonNode != null) { Iterator<String> itName = jsonNode.fieldNames(); while (itName.hasNext()) { String name = itName.next(); JsonNode valueNode = jsonNode.path(name); if (valueNode.isBoolean()) { variables.put(name, valueNode.booleanValue()); } else if (valueNode.isInt()) { variables.put(name, valueNode.intValue()); } else if (valueNode.isLong()) { variables.put(name, valueNode.longValue()); } else if (valueNode.isDouble()) { variables.put(name, valueNode.doubleValue()); } else if (valueNode.isTextual()) { variables.put(name, valueNode.textValue()); } else { // Not using asText() due to the fact we expect a null-value to be returned rather than en emtpy string // when node is not a simple value-node variables.put(name, valueNode.textValue()); }/*from ww w .j a v a 2s . c o m*/ } } return variables; }
From source file:org.eel.kitchen.jsonschema.validator.JsonResolver.java
/** * Resolve a schema node to the target schema node * * @see SchemaRegistry#get(URI)//from w ww . j a v a 2 s . c o m * * @param schemaNode the original schema node * @return the computed schema node * @throws JsonSchemaException ref resolution failure (dangling ref, ref * loop, etc) */ SchemaNode resolve(final SchemaNode schemaNode) throws JsonSchemaException { /* * All failures at this level are fatal */ final Message.Builder msg = Domain.REF_RESOLVING.newMessage().setKeyword("$ref").setFatal(true); /* * These two elements might change during ref resolving. Set them to * their initial values. */ SchemaContainer container = schemaNode.getContainer(); JsonNode node = schemaNode.getNode(); /* * This set will store all ABSOLUTE JSON references we encounter * during ref resolution. If there is an attempt to store an already * existing reference, this means a ref loop. * * We want to preserve insertion order, therefore we have to use a * LinkedHashSet. */ final Set<JsonRef> refs = new LinkedHashSet<JsonRef>(); /* * All elements below are set during the ref resolution process. */ JsonRef source, ref, target; JsonNode refNode; while (true) { /* * We break out immediately if either there is no $ref node, * or there exists one but it is not a text node (syntax validation * will catch that). */ refNode = node.path("$ref"); if (!refNode.isTextual()) break; /* * Similarly, the constructor will fail at this point iif the text * value of the node is not an URI: break, we want this caught by * syntax validation. */ try { ref = JsonRef.fromString(refNode.textValue()); } catch (JsonSchemaException ignored) { break; } /* * Compute the target ref. Try and insert it into the set of refs * already seen: if it has been already seen, there is a ref loop. */ source = container.getLocator(); target = source.resolve(ref); if (!refs.add(target)) { msg.setMessage("ref loop detected").addInfo("path", refs); throw new JsonSchemaException(msg.build()); } /* * Should we change schema context? We should if the source ref (the * one in the current container) does not contain the target ref. In * this case, get the new container from our schema registry. If we * cannot do that, this is an error condition, bail out. */ if (!source.contains(target)) container = registry.get(target.getLocator()); /* * Finally, compute the next node in the process. If it is missing, * we have a dangling JSON Pointer: this is an error condition. */ node = target.getFragment().resolve(container.getSchema()); if (node.isMissingNode()) { msg.setMessage("dangling JSON Reference").addInfo("ref", target); throw new JsonSchemaException(msg.build()); } } return new SchemaNode(container, node); }
From source file:org.openmhealth.reference.concordia.EnumValidator.java
/** * Verifies that any data point for this schema is one of the required enum * values.//from w w w .j a v a2 s . c o m * * @param schema * The schema to reference when validating the data. * * @param data * The data to validate. * * @param controller * The controller to use in the event that there is sub-data that * also needed to be validated. */ @Override public void validate(final StringSchema schema, final JsonNode data, final ValidationController controller) throws ConcordiaException { // If the data is null, we can ignore it because that value shouldn't // be in our list. Null will be caught by our default, required // validation, which will only allow this if the schema defines this // field as optional. if ((data == null) || (data instanceof NullNode)) { return; } // Get the value of this node. // We can also safely assume that this will return us a non-null value // as our default, required validation would have first run to ensure // that it is a TextNode. String value = data.textValue(); // Attempt to get the enum definition. Object enumField = schema.getAdditionalFields().get(ENUM_SCHEMA_FIELD); // If the definition exists, validate it. if (enumField != null) { // We can safely cast here, because our validation above took care // of this for us. @SuppressWarnings("unchecked") List<String> enumFieldIter = (List<String>) enumField; // Check each of our allowed values against the given value. if (!enumFieldIter.contains(value)) { // If one was not found, throw an exception. throw new ConcordiaException("The value, '" + value + "', is not in our list of acceptable values: " + enumField.toString()); } } }
From source file:io.robusta.rra.representation.implementation.JacksonRepresentation.java
/** * check if document is not null//from w w w . j a v a 2s .c o m * * @param key * @return */ protected boolean hasNotEmpty(String key) { throwIfNotObject(); JsonNode elt = asObject().get(key); if (elt == null || elt.isNull() || (elt.isTextual() && elt.textValue().isEmpty())) { // elt is null or empty string return false; } else { return true; } }
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManager.java
/** * Extract the "result" field from the get-mpu payload. * * @param objectNode The response JSON object. * @return MantaMultipartStatus extracted *//*from w w w . j a va 2s. co m*/ private MantaMultipartStatus extractMultipartStatusResult(final ObjectNode objectNode) { JsonNode resultNode = objectNode.get("result"); Validate.notNull(resultNode, "Unable to get result from response"); String result = resultNode.textValue(); Validate.notBlank(result, "Result field was blank in response"); if (result.equalsIgnoreCase("aborting")) { return MantaMultipartStatus.ABORTING; } if (result.equalsIgnoreCase("aborted")) { return MantaMultipartStatus.ABORTED; } if (result.equalsIgnoreCase("committing")) { return MantaMultipartStatus.COMMITTING; } if (result.equalsIgnoreCase("committed")) { return MantaMultipartStatus.COMMITTING; } return MantaMultipartStatus.UNKNOWN; }
From source file:org.eel.kitchen.jsonschema.keyword.DependenciesKeywordValidator.java
public DependenciesKeywordValidator(final JsonNode schema) { super("dependencies", NodeType.OBJECT); final Map<String, JsonNode> fields = JacksonUtils.nodeToMap(schema.get("dependencies")); final ImmutableMap.Builder<String, JsonNode> schemaBuilder = new ImmutableMap.Builder<String, JsonNode>(); final ImmutableSetMultimap.Builder<String, String> simpleBuilder = new ImmutableSetMultimap.Builder<String, String>(); String key;/* w w w . j a va 2 s .co m*/ JsonNode value; /* * Walk through the list of fields: * * - if we encounter an object, this is a schema dependency; * - otherwise this is a simple dependency. * * Remember that we went through syntax validation first, * so we are guaranteed about the correctness of the schema. */ for (final Map.Entry<String, JsonNode> entry : fields.entrySet()) { key = entry.getKey(); value = entry.getValue(); if (value.isObject()) { // schema dependency schemaBuilder.put(key, value); continue; } if (value.size() == 0) // single property dependency simpleBuilder.put(key, value.textValue()); else // multiple property dependency for (final JsonNode element : value) simpleBuilder.put(key, element.textValue()); } schemas = schemaBuilder.build(); simple = simpleBuilder.build(); }
From source file:com.alliander.osgp.shared.usermanagement.KeycloakClient.java
private boolean useSessionIdForClients(final JsonNode clientsObject) { final Iterator<JsonNode> clientNameNodeIterator = clientsObject.elements(); while (clientNameNodeIterator.hasNext()) { final JsonNode clientName = clientNameNodeIterator.next(); if (clientName == null || !clientName.isTextual()) { LOGGER.warn("value in clients is not a JSON text node with a client name"); continue; }//from w w w .ja va 2 s .c o m if (clientName.textValue().equals(this.loginClient)) { return true; } } return false; }