Example usage for com.fasterxml.jackson.core JsonPointer compile

List of usage examples for com.fasterxml.jackson.core JsonPointer compile

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonPointer compile.

Prototype

public static JsonPointer compile(String input) throws IllegalArgumentException 

Source Link

Document

Factory method that parses given input and construct matching pointer instance, if it represents a valid JSON Pointer: if not, a IllegalArgumentException is thrown.

Usage

From source file:com.meltmedia.dropwizard.crypto.Mocks.java

public static void mockPointer(Namespace namespace, String pointer) {
    when(namespace.get(Commands.POINTER)).thenReturn(JsonPointer.compile(pointer));
}

From source file:com.meltmedia.dropwizard.crypto.JsonPointerEditorTest.java

@Test
public void shouldGetValue() throws Exception {
    JsonNode node = mapper.readValue("{\"key\": {\"sub\": \"value\"}}", JsonNode.class);
    JsonPointer pointer = JsonPointer.compile("/key/sub");

    JsonPointerEditor editor = new JsonPointerEditor(node, pointer);
    assertThat("value", equalTo(editor.getValue().asText()));
}

From source file:com.reprezen.swagedit.model.Model.java

/**
 * Returns an empty model/*from w  w  w. j ava  2  s  .  co  m*/
 * 
 * @param schema
 * @return empty model
 */
public static Model empty(SwaggerSchema schema) {
    Model model = new Model(schema);
    ObjectNode root = new ObjectNode(model, null, JsonPointer.compile(""));
    root.setType(model.schema.getType(root));
    model.add(root);

    return model;
}

From source file:com.meltmedia.dropwizard.crypto.JsonPointerEditorTest.java

@Test
public void shouldSetValue() throws Exception {
    JsonNode node = mapper.readValue("{\"key\": {\"sub\": \"value\"}}", JsonNode.class);
    JsonPointer pointer = JsonPointer.compile("/key/sub");

    JsonPointerEditor editor = new JsonPointerEditor(node, pointer);
    editor.setValue(JsonNodeFactory.instance.textNode("updated"));
    assertThat("updated", equalTo(editor.getValue().asText()));
}

From source file:com.meltmedia.dropwizard.crypto.JsonPointerEditorTest.java

@Test
public void shouldUpdateArrayValue() throws Exception {
    JsonNode node = mapper.readValue("{\"key\": {\"sub\": [\"value1\", \"value2\", \"value3\"]}}",
            JsonNode.class);
    JsonPointer pointer = JsonPointer.compile("/key/sub/2");

    JsonPointerEditor editor = new JsonPointerEditor(node, pointer);
    editor.setValue(JsonNodeFactory.instance.textNode("updated"));
    assertThat("updated", equalTo(editor.getValue().asText()));
}

From source file:com.reprezen.swagedit.model.NodeDeserializer.java

protected ObjectNode deserializeObjectNode(JsonParser p, DeserializationContext context,
        JsonLocation startLocation) throws IllegalArgumentException, 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);

    final ObjectNode node = model.objectNode(parent, ptr);
    node.setStartLocation(createLocation(startLocation));

    while (p.nextToken() != JsonToken.END_OBJECT) {
        String name = p.getCurrentName();

        JsonPointer pp = JsonPointer.compile(ptr.toString() + "/" + name.replaceAll("/", "~1"));
        context.setAttribute(ATTRIBUTE_PARENT, node);
        context.setAttribute(ATTRIBUTE_POINTER, pp);

        AbstractNode v = deserialize(p, context);
        v.setProperty(name);//from   w  w  w  .  j  a  v a2s.  c  o  m
        node.put(name, v);
    }

    node.setEndLocation(createLocation(p.getCurrentLocation()));
    return node;
}

From source file:com.meltmedia.dropwizard.crypto.JsonPointerEditorTest.java

@Test
public void shouldAllowNodeTypeChange() throws Exception {
    JsonNode node = mapper.readValue("{\"key\": {\"sub\": \"value\"}}", JsonNode.class);
    JsonPointer pointer = JsonPointer.compile("/key/sub");

    JsonPointerEditor editor = new JsonPointerEditor(node, pointer);
    editor.setValue(factory.objectNode().set("subsub", factory.textNode("nested")));
    assertThat("nested", equalTo(node.at("/key/sub/subsub").asText()));
}

From source file:com.reprezen.swagedit.editor.hyperlinks.DefinitionHyperlinkDetector.java

protected JsonPointer getRequiredPropertyPath(SwaggerDocument doc, HyperlinkInfo info, JsonPointer pointer) {
    Matcher matcher = Pattern.compile(REQUIRED_PATTERN).matcher(pointer.toString());
    String containerPath = null;/*from   w  w w.ja v a2 s .co m*/
    if (matcher.find()) {
        containerPath = matcher.group(1);
    }

    if (emptyToNull(containerPath) == null) {
        return null;
    }

    AbstractNode container = doc.getModel().find(JsonPointer.compile(containerPath));
    if (container.get("properties") != null && container.get("properties").get(info.text) != null) {
        return container.get("properties").get(info.text).getPointer();
    } else {
        return null;
    }
}

From source file:com.reprezen.swagedit.json.references.JsonReferenceFactory.java

/**
 * Returns a simple reference if the value node points to a definition inside the same document.
 * //from   ww w  .ja  v  a2s  .co  m
 * @param baseURI
 * @param value
 * @return reference
 */
public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
    if (valueNode.isArray() || valueNode.isObject()) {
        return null;
    }

    final Object value = valueNode.asValue().getValue();
    if (!(value instanceof String)) {
        return null;
    }

    String stringValue = (String) value;
    if (Strings.emptyToNull(stringValue) == null || stringValue.startsWith("#") || stringValue.contains("/")) {
        return null;
    }

    final Model model = valueNode.getModel();
    if (model != null) {
        JsonPointer ptr = JsonPointer.compile("/definitions/" + value);
        AbstractNode target = model.find(ptr);
        if (target != null) {
            return new JsonReference.SimpleReference(baseURI, ptr, valueNode);
        }
    }

    return null;
}

From source file:com.reprezen.swagedit.editor.hyperlinks.DefinitionHyperlinkDetector.java

protected JsonPointer getTagDefinitionPath(SwaggerDocument doc, HyperlinkInfo info, JsonPointer pointer) {
    AbstractNode node = doc.getModel().find(JsonPointer.compile("/definitions/" + info.text));

    return node != null ? node.getPointer() : null;
}