use of com.fasterxml.jackson.databind.node.ArrayNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class SwaggerSchema method allowJsonRefInContext.
public void allowJsonRefInContext(String jsonReferenceContext, boolean allow) {
if (jsonRefContexts.get(jsonReferenceContext) == null) {
throw new IllegalArgumentException("Invalid JSON Reference Context: " + jsonReferenceContext);
}
// special case
if (SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT.equals(jsonReferenceContext)) {
allowJsonRefInSecurityDefinitionsObject(allow);
return;
}
ArrayNode definition = (ArrayNode) jsonRefContexts.get(jsonReferenceContext);
// should preserve order of the original ArrayNode._children
List<JsonNode> children = Lists.newArrayList(definition.elements());
int indexOfJsonReference = children.indexOf(refToJsonReferenceNode);
boolean alreadyHasJsonReference = indexOfJsonReference > -1;
if (allow) {
if (!alreadyHasJsonReference) {
definition.add(refToJsonReferenceNode.deepCopy());
}
} else {
// disallow
if (alreadyHasJsonReference) {
definition.remove(indexOfJsonReference);
}
}
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class MultipleSwaggerErrorBuilder method getHumanFriendlyText.
protected String getHumanFriendlyText(JsonNode swaggerSchemaNode, final String defaultValue) {
JsonNode title = swaggerSchemaNode.get("title");
if (title != null) {
return title.asText();
}
// nested array
if (swaggerSchemaNode.get("items") != null) {
return getHumanFriendlyText(swaggerSchemaNode.get("items"), defaultValue);
}
// "$ref":"#/definitions/headerParameterSubSchema"
JsonNode ref = swaggerSchemaNode.get("$ref");
if (ref != null) {
return getLabelForRef(ref.asText());
}
// Auxiliary oneOf in "oneOf": [ { "$ref": "#/definitions/securityRequirement" }]
JsonNode oneOf = swaggerSchemaNode.get("oneOf");
if (oneOf != null) {
if (oneOf instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) oneOf;
if (arrayNode.size() > 0) {
Iterator<String> labels = transform(arrayNode.elements(), new Function<JsonNode, String>() {
@Override
public String apply(JsonNode el) {
return getHumanFriendlyText(el, defaultValue);
}
});
return "[" + Joiner.on(", ").join(labels) + "]";
}
}
}
return defaultValue;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jackson-databind by FasterXML.
the class ObjectReaderTest method testTreeToValue.
/*
/**********************************************************
/* Test methods, ObjectCodec
/**********************************************************
*/
public void testTreeToValue() throws Exception {
ArrayNode n = MAPPER.createArrayNode();
n.add("xyz");
ObjectReader r = MAPPER.readerFor(String.class);
List<?> list = r.treeToValue(n, List.class);
assertEquals(1, list.size());
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jackson-databind by FasterXML.
the class NodeMergeTest method testObjectDeepUpdate.
public void testObjectDeepUpdate() throws Exception {
ObjectNode base = MAPPER.createObjectNode();
ObjectNode props = base.putObject("props");
props.put("base", 123);
props.put("value", 456);
ArrayNode a = props.putArray("array");
a.add(true);
base.putNull("misc");
assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'props':{'value':true, 'extra':25.5, 'array' : [ 3 ]}}")));
assertEquals(2, base.size());
ObjectNode resultProps = (ObjectNode) base.get("props");
assertEquals(4, resultProps.size());
assertEquals(123, resultProps.path("base").asInt());
assertTrue(resultProps.path("value").asBoolean());
assertEquals(25.5, resultProps.path("extra").asDouble());
JsonNode n = resultProps.get("array");
assertEquals(ArrayNode.class, n.getClass());
assertEquals(2, n.size());
assertEquals(3, n.get(1).asInt());
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project Activiti by Activiti.
the class BaseBpmnJsonConverter method addFormProperties.
protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
if (CollectionUtils.isEmpty(formProperties))
return;
ObjectNode formPropertiesNode = objectMapper.createObjectNode();
ArrayNode propertiesArrayNode = objectMapper.createArrayNode();
for (FormProperty property : formProperties) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
if (StringUtils.isNotEmpty(property.getExpression())) {
propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
} else {
propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
}
if (StringUtils.isNotEmpty(property.getVariable())) {
propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
} else {
propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
}
if (StringUtils.isNotEmpty(property.getDatePattern())) {
propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern());
}
if (CollectionUtils.isNotEmpty(property.getFormValues())) {
ArrayNode valuesNode = objectMapper.createArrayNode();
for (FormValue formValue : property.getFormValues()) {
ObjectNode valueNode = objectMapper.createObjectNode();
valueNode.put(PROPERTY_FORM_ENUM_VALUES_NAME, formValue.getName());
valueNode.put(PROPERTY_FORM_ENUM_VALUES_ID, formValue.getId());
valuesNode.add(valueNode);
}
propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
}
propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired());
propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable());
propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable());
propertiesArrayNode.add(propertyItemNode);
}
formPropertiesNode.put("formProperties", propertiesArrayNode);
propertiesNode.put(PROPERTY_FORM_PROPERTIES, formPropertiesNode);
}
Aggregations