类com.fasterxml.jackson.core.JsonPointer源码实例Demo

下面列出了怎么用com.fasterxml.jackson.core.JsonPointer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: onos   文件: JsonDataModelTree.java
@Override
public void attach(String path, DataModelTree tree) throws WorkflowException {

    if (root == null || root instanceof MissingNode) {
        throw new WorkflowException("Invalid root node");
    }

    JsonPointer ptr = JsonPointer.compile(path);

    if (!(tree instanceof JsonDataModelTree)) {
        throw new WorkflowException("Invalid subTree(" + tree + ")");
    }
    JsonNode attachingNode = ((JsonDataModelTree) tree).root();

    attach(ptr, attachingNode);
}
 
源代码2 项目: centraldogma   文件: MetadataService.java
/**
 * Adds a {@link Token} of the specified {@code appId} to the specified {@code projectName}.
 */
public CompletableFuture<Revision> addToken(Author author, String projectName,
                                            String appId, ProjectRole role) {
    requireNonNull(author, "author");
    requireNonNull(projectName, "projectName");
    requireNonNull(appId, "appId");
    requireNonNull(role, "role");

    return getTokens().thenCompose(tokens -> {
        final Token token = tokens.appIds().get(appId);
        checkArgument(token != null, "Token not found: " + appId);

        final TokenRegistration registration = new TokenRegistration(appId, role,
                                                                     UserAndTimestamp.of(author));
        final JsonPointer path = JsonPointer.compile("/tokens" + encodeSegment(registration.id()));
        final Change<JsonNode> change =
                Change.ofJsonPatch(METADATA_JSON,
                                   asJsonArray(new TestAbsenceOperation(path),
                                               new AddOperation(path, Jackson.valueToTree(registration))));
        final String commitSummary = "Add a token '" + registration.id() +
                                     "' to the project '" + projectName + "' with a role '" + role + '\'';
        return metadataRepo.push(projectName, Project.REPO_DOGMA, author, commitSummary, change);
    });
}
 
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    Model model = doc.getModel();
    AbstractNode node = model.find(pointer);
    List<AbstractNode> nodes = model.findByType(JsonPointer.compile("/definitions/operation"));
    Iterator<AbstractNode> it = nodes.iterator();

    AbstractNode found = null;
    while (it.hasNext() && found == null) {
        AbstractNode current = it.next();
        AbstractNode value = current.get("operationId");

        if (value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue())) {
            found = value;
        }
    }

    if (found != null) {
        IRegion target = doc.getRegion(found.getPointer());
        if (target != null) {
            return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
        }
    }

    return null;
}
 
源代码4 项目: centraldogma   文件: MetadataService.java
/**
 * Adds the specified {@code member} to the {@link ProjectMetadata} of the specified {@code projectName}
 * with the specified {@code projectRole}.
 */
public CompletableFuture<Revision> addMember(Author author, String projectName,
                                             User member, ProjectRole projectRole) {
    requireNonNull(author, "author");
    requireNonNull(projectName, "projectName");
    requireNonNull(member, "member");
    requireNonNull(projectRole, "projectRole");

    final Member newMember = new Member(member, projectRole, UserAndTimestamp.of(author));
    final JsonPointer path = JsonPointer.compile("/members" + encodeSegment(newMember.id()));
    final Change<JsonNode> change =
            Change.ofJsonPatch(METADATA_JSON,
                               asJsonArray(new TestAbsenceOperation(path),
                                           new AddOperation(path, Jackson.valueToTree(newMember))));
    final String commitSummary =
            "Add a member '" + newMember.id() + "' to the project '" + projectName + '\'';
    return metadataRepo.push(projectName, Project.REPO_DOGMA, author, commitSummary, change);
}
 
源代码5 项目: centraldogma   文件: MetadataService.java
private CompletableFuture<Revision> removeToken(String projectName, Author author, String appId,
                                                boolean quiet) {
    final String commitSummary = "Remove the token '" + appId + "' from the project '" + projectName + '\'';
    return metadataRepo.push(
            projectName, Project.REPO_DOGMA, author, commitSummary,
            () -> fetchMetadata(projectName).thenApply(metadataWithRevision -> {
                final ImmutableList.Builder<JsonPatchOperation> patches = ImmutableList.builder();
                final ProjectMetadata metadata = metadataWithRevision.object();
                metadata.repos().values()
                        .stream().filter(repo -> repo.perTokenPermissions().containsKey(appId))
                        .forEach(r -> patches.add(
                                new RemoveOperation(perTokenPermissionPointer(r.name(), appId))));
                if (quiet) {
                    patches.add(new RemoveIfExistsOperation(JsonPointer.compile("/tokens" +
                                                                                encodeSegment(appId))));
                } else {
                    patches.add(new RemoveOperation(JsonPointer.compile("/tokens" +
                                                                        encodeSegment(appId))));
                }
                final Change<JsonNode> change =
                        Change.ofJsonPatch(METADATA_JSON, Jackson.valueToTree(patches.build()));
                return HolderWithRevision.of(change, metadataWithRevision.revision());
            })
    );
}
 
源代码6 项目: centraldogma   文件: DiffProcessor.java
DiffProcessor(ReplaceMode replaceMode, final Supplier<Map<JsonPointer, JsonNode>> unchangedValuesSupplier) {
    this.replaceMode = replaceMode;
    this.unchangedValuesSupplier = new Supplier<Map<JsonPointer, JsonNode>>() {

        @Nullable
        private Map<JsonPointer, JsonNode> unchangedValues;

        @Override
        public Map<JsonPointer, JsonNode> get() {
            if (unchangedValues == null) {
                unchangedValues = unchangedValuesSupplier.get();
            }
            return unchangedValues;
        }
    };
}
 
源代码7 项目: KaiZen-OpenAPI-Editor   文件: OpenApi3Validator.java
protected void validateOperationIdReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
    JsonPointer schemaPointer = JsonPointer.compile("/definitions/link/properties/operationId");

    if (node != null && node.getType() != null && schemaPointer.equals(node.getType().getPointer())) {
        List<AbstractNode> nodes = model.findByType(operationPointer);
        Iterator<AbstractNode> it = nodes.iterator();

        boolean found = false;
        while (it.hasNext() && !found) {
            AbstractNode current = it.next();
            AbstractNode value = current.get("operationId");

            found = value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue());
        }

        if (!found) {
            errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_invalid_operation_id));
        }
    }
}
 
void addTestData(Object value) {
    JsonPointer ptr = getPointer(null, true, true);
    if (!testDataCache.exists(ptr)) {
        try {
            testDataCache.set(ptr, value);
        } catch (CacheException e) {
            LOGGER.error("Unable to update test data cache for " + ptr, e);
        }
    }
}
 
源代码9 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public Object get(JsonPointer ptr) throws CacheException {
    Object result;
    if (root == null) {
        result = null;
    } else {
        try {
            JsonNode node = root.at(ptr);
            switch (node.getNodeType()) {
                case ARRAY:
                case OBJECT:
                    result = node;
                    break;
                case BINARY:
                    result = node.binaryValue();
                    break;
                case BOOLEAN:
                    result = node.booleanValue();
                    break;
                case NUMBER:
                    result = node.numberValue();
                    break;
                case POJO:
                    result = ((POJONode) node).getPojo();
                    break;
                case STRING:
                    result = node.textValue();
                    break;
                default:
                    result = null;
                    break;
            }
        } catch (IOException e) {
            throw new CacheException(e);
        }
    }
    return result;
}
 
源代码10 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public Number getNumber(JsonPointer ptr, Number defaultValue) throws CacheException {
    Objects.requireNonNull(defaultValue, "defaultValue is required");
    Number result;
    if (exists(ptr)) {
        result = getNumber(ptr);
    } else {
        set(ptr, defaultValue);
        result = defaultValue;
    }
    return result;
}
 
源代码11 项目: centraldogma   文件: DiffProcessor.java
void valueReplaced(final JsonPointer pointer, final JsonNode oldValue, final JsonNode newValue) {
    switch (replaceMode) {
        case RFC6902:
            diffs.add(new ReplaceOperation(pointer, newValue));
            break;
        case SAFE:
            diffs.add(new SafeReplaceOperation(pointer, oldValue, newValue));
            break;
    }
}
 
源代码12 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public BigInteger getBigInteger(JsonPointer ptr, BigInteger defaultValue) throws CacheException {
    Objects.requireNonNull(defaultValue, "defaultValue is required");
    BigInteger result;
    if (exists(ptr)) {
        result = getBigInteger(ptr);
    } else {
        set(ptr, defaultValue);
        result = defaultValue;
    }
    return result;
}
 
源代码13 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public double getDouble(JsonPointer ptr, double defaultValue) throws CacheException {
    Objects.requireNonNull(defaultValue, "defaultValue is required");
    double result;
    if (exists(ptr)) {
        result = getDouble(ptr);
    } else {
        set(ptr, defaultValue);
        result = defaultValue;
    }
    return result;
}
 
源代码14 项目: KaiZen-OpenAPI-Editor   文件: JsonDocument.java
public IRegion getRegion(JsonPointer pointer) {
    Model model = getModel();
    if (model == null) {
        return null;
    }

    AbstractNode node = model.find(pointer);
    if (node == null) {
        return new Region(0, 0);
    }

    Position position = node.getPosition(this);

    return new Region(position.getOffset(), position.getLength());
}
 
@Test
public void test() throws URISyntaxException {
    JsonReferenceFactory factory = new JsonReferenceFactory();

    JsonReference result = factory.doCreate("#/definitions/Foo", null);

    assertEquals(new URI(null, null, "/definitions/Foo"), result.getUri());
    assertTrue(result.isLocal());
    assertFalse(result.isAbsolute());
    assertEquals(JsonPointer.compile("/definitions/Foo"), result.getPointer());
}
 
源代码16 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public String getString(JsonPointer ptr, String defaultValue) {
    Objects.requireNonNull(defaultValue, "defaultValue is required");
    String result;
    if (exists(ptr)) {
        result = getString(ptr);
    } else {
        set(ptr, defaultValue);
        result = defaultValue;
    }
    return result;
}
 
源代码17 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public BigDecimal getBigDecimal(JsonPointer ptr, BigDecimal defaultValue) throws CacheException {
    Objects.requireNonNull(defaultValue, "defaultValue is required");
    BigDecimal result;
    if (exists(ptr)) {
        result = getBigDecimal(ptr);
    } else {
        set(ptr, defaultValue);
        result = defaultValue;
    }
    return result;
}
 
源代码18 项目: onos   文件: JsonDataModelTree.java
/**
 * Gets json node on specific json pointer as ArrayNode.
 *
 * @param ptr json pointer
 * @return ArrayNode type json node on specific json pointer.
 * @throws WorkflowException workflow exception
 */
public ArrayNode arrayAt(JsonPointer ptr) throws WorkflowException {
    if (root == null || root instanceof MissingNode) {
        throw new WorkflowException("Invalid root node");
    }
    JsonNode node = root.at(ptr);
    if (node instanceof MissingNode) {
        return null;
    }
    if (!(node instanceof ArrayNode)) {
        throw new WorkflowException("Invalid node(" + node + ") at " + ptr);
    }
    return (ArrayNode) node;
}
 
源代码19 项目: KaiZen-OpenAPI-Editor   文件: NodeDeserializer.java
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;
}
 
源代码20 项目: liiklus   文件: JsonSchemaPreProcessorTest.java
private JsonSchemaPreProcessor getProcessor(boolean allowDeprecatedProperties) {
    return new JsonSchemaPreProcessor(
            getSchema("basic.yml"),
            JsonPointer.compile("/eventType"),
            allowDeprecatedProperties
    );
}
 
@Test
public void test4() throws URISyntaxException {
    JsonReferenceFactory factory = new JsonReferenceFactory();

    JsonReference result = factory.doCreate("file://path/to/file/doc.yaml#/definitions/Foo", null);

    assertEquals(URI.create("file://path/to/file/doc.yaml#/definitions/Foo"), result.getUri());
    assertFalse(result.isLocal());
    assertTrue(result.isAbsolute());
    assertEquals(JsonPointer.compile("/definitions/Foo"), result.getPointer());
}
 
源代码22 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public JsonCache add(String path, int value) {
    return add(JsonPointer.compile(path), value);
}
 
源代码23 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public long getLong(String path, long defaultValue) throws CacheException {
    return getLong(JsonPointer.compile(path), defaultValue);
}
 
源代码24 项目: centraldogma   文件: RemoveOperation.java
@JsonCreator
public RemoveOperation(@JsonProperty("path") final JsonPointer path) {
    super("remove", path);
}
 
源代码25 项目: openapi-generator   文件: JsonCacheImpl.java
private ChildCacheImpl(JsonCache parent, JsonPointer basePtr) {
    this.parent = parent;
    this.basePtr = basePtr;
}
 
源代码26 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public short getShort(JsonPointer ptr) {
    return root == null ? (short) 0 : root.at(ptr).shortValue();
}
 
源代码27 项目: mybatis-jackson   文件: TreeNodeLazyWrapper.java
@Override
public TreeNode at(JsonPointer jp) {
    return tree().at(jp);
}
 
public ReferenceTypeDefinition(JsonSchema schema, JsonPointer pointer, JsonNode definition) {
    super(schema, pointer, definition, JsonType.UNDEFINED);
}
 
源代码29 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public JsonCache set(String path, long value) throws CacheException {
    parent.set(basePtr.append(JsonPointer.compile(path)), value);
    return this;
}
 
源代码30 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public JsonCache add(String path, BigDecimal value) throws CacheException {
    parent.add(basePtr.append(JsonPointer.compile(path)), value);
    return this;
}
 
 同包方法