use of com.fasterxml.jackson.core.JsonPointer in project KaiZen-OpenAPI-Editor by RepreZen.
the class NodeDeserializer method deserializeValueNode.
protected ValueNode deserializeValueNode(JsonParser p, DeserializationContext context, JsonLocation startLocation) throws IOException {
final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);
Object v = context.readValue(p, Object.class);
ValueNode node = model.valueNode(parent, ptr, v);
node.setStartLocation(createLocation(startLocation));
node.setEndLocation(createLocation(p.getCurrentLocation()));
return node;
}
use of com.fasterxml.jackson.core.JsonPointer in project KaiZen-OpenAPI-Editor by RepreZen.
the class CompositeSchema method getType.
/**
* Returns the type that is reachable by the given pointer inside the JSON schema. <br/>
*
* Examples of pointers: <br/>
* - /properties/swagger <br/>
* - /definitions/paths
*
* @param pointer
* @return type
*/
public TypeDefinition getType(String reference) {
if (Strings.emptyToNull(reference) == null) {
return swaggerType.getType();
}
JsonPointer pointer = pointer(reference);
JsonSchema schema = getSchema(baseURI(reference));
return schema.get(pointer);
}
use of com.fasterxml.jackson.core.JsonPointer in project KaiZen-OpenAPI-Editor by RepreZen.
the class DefinitionHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
JsonPointer targetPath;
if (pointer.toString().matches(REQUIRED_PATTERN)) {
targetPath = getRequiredPropertyPath(doc, info, pointer);
} else {
targetPath = getTagDefinitionPath(doc, info, pointer);
}
if (targetPath == null) {
return null;
}
IRegion target = doc.getRegion(targetPath);
if (target == null) {
return null;
}
return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
use of com.fasterxml.jackson.core.JsonPointer in project torodb by torodb.
the class ConfigUtils method mergeParam.
public static ObjectNode mergeParam(ObjectMapper objectMapper, ObjectNode configRootNode, String pathAndProp, String value) throws Exception {
if (JsonPointer.compile(pathAndProp).equals(JsonPointer.compile("/"))) {
return (ObjectNode) objectMapper.readTree(value);
}
String path = pathAndProp.substring(0, pathAndProp.lastIndexOf("/"));
String prop = pathAndProp.substring(pathAndProp.lastIndexOf("/") + 1);
JsonPointer pathPointer = JsonPointer.compile(path);
JsonNode pathNode = configRootNode.at(pathPointer);
if (pathNode.isMissingNode() || pathNode.isNull()) {
JsonPointer currentPointer = pathPointer;
JsonPointer childOfCurrentPointer = null;
List<JsonPointer> missingPointers = new ArrayList<>();
List<JsonPointer> childOfMissingPointers = new ArrayList<>();
do {
if (pathNode.isMissingNode() || pathNode.isNull()) {
missingPointers.add(0, currentPointer);
childOfMissingPointers.add(0, childOfCurrentPointer);
}
childOfCurrentPointer = currentPointer;
currentPointer = currentPointer.head();
pathNode = configRootNode.at(currentPointer);
} while (pathNode.isMissingNode() || pathNode.isNull());
for (int missingPointerIndex = 0; missingPointerIndex < missingPointers.size(); missingPointerIndex++) {
final JsonPointer missingPointer = missingPointers.get(missingPointerIndex);
final JsonPointer childOfMissingPointer = childOfMissingPointers.get(missingPointerIndex);
final List<JsonNode> newNodes = new ArrayList<>();
if (pathNode.isObject()) {
((ObjectNode) pathNode).set(missingPointer.last().getMatchingProperty(), createNode(childOfMissingPointer, newNodes));
} else if (pathNode.isArray() && missingPointer.last().mayMatchElement()) {
for (int index = ((ArrayNode) pathNode).size(); index < missingPointer.last().getMatchingIndex() + 1; index++) {
((ArrayNode) pathNode).add(createNode(childOfMissingPointer, newNodes));
}
} else {
throw new RuntimeException("Cannot set param " + pathAndProp + "=" + value);
}
pathNode = newNodes.get(newNodes.size() - 1);
}
}
Object valueAsObject;
try {
valueAsObject = objectMapper.readValue(value, Object.class);
} catch (JsonMappingException jsonMappingException) {
throw JsonMappingException.wrapWithPath(jsonMappingException, configRootNode, path.substring(1) + "/" + prop);
}
if (pathNode instanceof ObjectNode) {
ObjectNode objectNode = (ObjectNode) pathNode;
if (valueAsObject != null) {
JsonNode valueNode = objectMapper.valueToTree(valueAsObject);
objectNode.set(prop, valueNode);
} else {
objectNode.remove(prop);
}
} else if (pathNode instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) pathNode;
Integer index = Integer.valueOf(prop);
if (valueAsObject != null) {
JsonNode valueNode = objectMapper.valueToTree(valueAsObject);
arrayNode.set(index, valueNode);
} else {
arrayNode.remove(index);
}
}
return configRootNode;
}
use of com.fasterxml.jackson.core.JsonPointer in project torodb by torodb.
the class ConfigUtils method getParam.
public static <T> JsonNode getParam(T config, String pathAndProp) throws Exception {
XmlMapper xmlMapper = xmlMapper();
JsonNode configNode = xmlMapper.valueToTree(config);
if (JsonPointer.compile(pathAndProp).equals(JsonPointer.compile("/"))) {
return configNode;
}
JsonPointer pathPointer = JsonPointer.compile(pathAndProp);
JsonNode pathNode = configNode.at(pathPointer);
if (pathNode.isMissingNode() || pathNode.isNull()) {
return null;
}
return pathNode;
}
Aggregations