本文整理了Java中com.linecorp.centraldogma.internal.Jackson.readTree()
方法的一些代码示例,展示了Jackson.readTree()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jackson.readTree()
方法的具体详情如下:
包路径:com.linecorp.centraldogma.internal.Jackson
类名称:Jackson
方法名:readTree
暂无
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
/**
* Returns a newly-created {@link Entry} of a JSON file.
*
* @param revision the revision of the JSON file
* @param path the path of the JSON file
* @param content the content of the JSON file
*
* @throws JsonParseException if the {@code content} is not a valid JSON
*/
public static Entry<JsonNode> ofJson(Revision revision, String path, String content)
throws JsonParseException {
return ofJson(revision, path, Jackson.readTree(content));
}
代码示例来源:origin: line/centraldogma
/**
* Returns a newly-created {@link Entry} of a JSON file.
*
* @param revision the revision of the JSON file
* @param path the path of the JSON file
* @param content the content of the JSON file
*
* @throws JsonParseException if the {@code content} is not a valid JSON
*/
public static Entry<JsonNode> ofJson(Revision revision, String path, String content)
throws JsonParseException {
return ofJson(revision, path, Jackson.readTree(content));
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* Returns a newly-created {@link Entry} of a JSON file.
*
* @param revision the revision of the JSON file
* @param path the path of the JSON file
* @param content the content of the JSON file
*
* @throws JsonParseException if the {@code content} is not a valid JSON
*/
public static Entry<JsonNode> ofJson(Revision revision, String path, String content)
throws JsonParseException {
return ofJson(revision, path, Jackson.readTree(content));
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_JSON}.
*
* @param path the path of the file
* @param jsonText the content of the file
*
* @throws ChangeFormatException if the specified {@code jsonText} is not a valid JSON
*/
static Change<JsonNode> ofJsonUpsert(String path, String jsonText) {
requireNonNull(jsonText, "jsonText");
final JsonNode jsonNode;
try {
jsonNode = Jackson.readTree(jsonText);
} catch (IOException e) {
throw new ChangeFormatException("failed to read a value as a JSON tree", e);
}
return new DefaultChange<>(path, ChangeType.UPSERT_JSON, jsonNode);
}
代码示例来源:origin: line/centraldogma
static Revision extractRevision(String jsonString) {
try {
final JsonNode jsonNode = Jackson.readTree(jsonString);
return new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), ""));
} catch (Exception e) {
throw new StorageException("failed to extract revision from " + jsonString, e);
}
}
代码示例来源:origin: line/centraldogma
/**
* Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_JSON}.
*
* @param path the path of the file
* @param jsonText the content of the file
*
* @throws ChangeFormatException if the specified {@code jsonText} is not a valid JSON
*/
static Change<JsonNode> ofJsonUpsert(String path, String jsonText) {
requireNonNull(jsonText, "jsonText");
final JsonNode jsonNode;
try {
jsonNode = Jackson.readTree(jsonText);
} catch (IOException e) {
throw new ChangeFormatException("failed to read a value as a JSON tree", e);
}
return new DefaultChange<>(path, ChangeType.UPSERT_JSON, jsonNode);
}
代码示例来源:origin: line/centraldogma
/**
* Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
*
* @param path the path of the file
* @param jsonPatchText the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a>
*
* @throws ChangeFormatException if the specified {@code jsonPatchText} is not a valid JSON
*/
static Change<JsonNode> ofJsonPatch(String path, String jsonPatchText) {
requireNonNull(jsonPatchText, "jsonPatchText");
final JsonNode jsonPatchNode;
try {
jsonPatchNode = Jackson.readTree(jsonPatchText);
} catch (IOException e) {
throw new ChangeFormatException("failed to read a value as a JSON tree", e);
}
return ofJsonPatch(path, jsonPatchNode);
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
*
* @param path the path of the file
* @param jsonPatchText the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a>
*
* @throws ChangeFormatException if the specified {@code jsonPatchText} is not a valid JSON
*/
static Change<JsonNode> ofJsonPatch(String path, String jsonPatchText) {
requireNonNull(jsonPatchText, "jsonPatchText");
final JsonNode jsonPatchNode;
try {
jsonPatchNode = Jackson.readTree(jsonPatchText);
} catch (IOException e) {
throw new ChangeFormatException("failed to read a value as a JSON tree", e);
}
return ofJsonPatch(path, jsonPatchNode);
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
/**
* Returns the JSON representation of {@link #content()}.
*
* @return the {@link JsonNode} parsed from the {@link #content()}
*
* @throws IllegalStateException if this {@link Entry} is a directory
* @throws JsonParseException if failed to parse the {@link #content()} as JSON
*/
public JsonNode contentAsJson() throws JsonParseException {
final T content = content();
if (content instanceof JsonNode) {
return (JsonNode) content;
}
return Jackson.readTree(contentAsText());
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
static Revision extractRevision(String jsonString) {
try {
final JsonNode jsonNode = Jackson.readTree(jsonString);
return new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), ""));
} catch (Exception e) {
throw new StorageException("failed to extract revision from " + jsonString, e);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* Returns the JSON representation of the specified content.
*
* @return the {@link JsonNode} parsed from the content
*
* @throws IllegalStateException if the content is {@code null}
* @throws JsonParseException if failed to parse the content as JSON
*/
default JsonNode contentAsJson() throws JsonParseException {
final T content = content();
if (content instanceof JsonNode) {
return (JsonNode) content;
}
return Jackson.readTree(contentAsText());
}
代码示例来源:origin: line/centraldogma
/**
* Returns the JSON representation of the specified content.
*
* @return the {@link JsonNode} parsed from the content
*
* @throws IllegalStateException if the content is {@code null}
* @throws JsonParseException if failed to parse the content as JSON
*/
default JsonNode contentAsJson() throws JsonParseException {
final T content = content();
if (content instanceof JsonNode) {
return (JsonNode) content;
}
return Jackson.readTree(contentAsText());
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
static Revision extractRevision(String jsonString) {
try {
final JsonNode jsonNode = Jackson.readTree(jsonString);
return new Revision(Jackson.textValue(jsonNode.get(FIELD_NAME_REVISION), ""));
} catch (Exception e) {
throw new StorageException("failed to extract revision from " + jsonString, e);
}
}
代码示例来源:origin: line/centraldogma
@Test
public void rootShouldBeObjectNode() throws IOException {
final JsonNode arrayJson1 = readTree("[1, 2, 3]");
final JsonNode arrayJson2 = readTree("[3, 4, 5]");
assertThatThrownBy(() -> Jackson.mergeTree(arrayJson1, arrayJson2))
.isExactlyInstanceOf(QueryExecutionException.class)
.hasMessageContaining("/ type: ARRAY (expected: OBJECT)");
}
代码示例来源:origin: line/centraldogma
@Test
public void createRepository() throws IOException {
final AggregatedHttpMessage aRes = createRepository("myRepo");
final HttpHeaders headers = aRes.headers();
assertThat(headers.status()).isEqualTo(HttpStatus.CREATED);
final String location = headers.get(HttpHeaderNames.LOCATION);
assertThat(location).isEqualTo("/api/v1/projects/myPro/repos/myRepo");
final JsonNode jsonNode = Jackson.readTree(aRes.content().toStringUtf8());
assertThat(jsonNode.get("name").asText()).isEqualTo("myRepo");
assertThat(jsonNode.get("headRevision").asInt()).isOne();
assertThat(jsonNode.get("createdAt").asText()).isNotNull();
}
代码示例来源:origin: line/centraldogma
@Test
public void createProject() throws IOException {
final AggregatedHttpMessage aRes = createProject("myPro");
final HttpHeaders headers = aRes.headers();
assertThat(headers.status()).isEqualTo(HttpStatus.CREATED);
final String location = headers.get(HttpHeaderNames.LOCATION);
assertThat(location).isEqualTo("/api/v1/projects/myPro");
final JsonNode jsonNode = Jackson.readTree(aRes.content().toStringUtf8());
assertThat(jsonNode.get("name").asText()).isEqualTo("myPro");
assertThat(jsonNode.get("createdAt").asText()).isNotNull();
}
代码示例来源:origin: line/centraldogma
@Test
public void mergeFiles() throws Exception {
doAnswer(invocation -> {
final AsyncMethodCallback<MergedEntry> callback = invocation.getArgument(4);
callback.onComplete(new MergedEntry(new TRevision(1), TEntryType.JSON, "{\"foo\": \"bar\"}",
ImmutableList.of("/a.json", "/b.json")));
return null;
}).when(iface).mergeFiles(any(), any(), any(), any(), any());
assertThat(client.mergeFiles("project", "repo", new Revision(1),
MergeQuery.ofJson(ImmutableList.of(MergeSource.ofOptional("/a.json"),
MergeSource.ofRequired("/b.json"))))
.get())
.isEqualTo(com.linecorp.centraldogma.common.MergedEntry.of(
new Revision(1), EntryType.JSON, Jackson.readTree("{\"foo\": \"bar\"}"),
ImmutableList.of("/a.json", "/b.json")));
verify(iface).mergeFiles(eq("project"), eq("repo"), any(), any(), any());
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-legacy-shaded
public static com.linecorp.centraldogma.common.Entry<?> convert(
com.linecorp.centraldogma.common.Revision revision, Entry entry) {
switch (entry.getType()) {
case JSON:
try {
final JsonNode value = Jackson.readTree(entry.getContent());
return com.linecorp.centraldogma.common.Entry.ofJson(revision, entry.getPath(), value);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
case TEXT:
return com.linecorp.centraldogma.common.Entry.ofText(revision, entry.getPath(),
entry.getContent());
case DIRECTORY:
return com.linecorp.centraldogma.common.Entry.ofDirectory(revision, entry.getPath());
default:
throw new IllegalArgumentException("unsupported entry type: " + entry.getType());
}
}
代码示例来源:origin: line/centraldogma
@Test
public void editFileWithJsonPatch() throws IOException {
addFooJson();
final AggregatedHttpMessage res1 = editFooJson();
final String expectedJson =
'{' +
" \"revision\": 3," +
" \"pushedAt\": \"${json-unit.ignore}\"" +
'}';
final String actualJson = res1.content().toStringUtf8();
assertThatJson(actualJson).isEqualTo(expectedJson);
final AggregatedHttpMessage res2 = httpClient().get(CONTENTS_PREFIX + "/foo.json").aggregate().join();
assertThat(Jackson.readTree(res2.content().toStringUtf8()).get("content").get("a").textValue())
.isEqualToIgnoringCase("baz");
}
代码示例来源:origin: line/centraldogma
@Test
public void deleteFile() throws IOException {
addFooJson();
addBarTxt();
final String body =
'{' +
" \"path\": \"/foo.json\"," +
" \"type\": \"REMOVE\"," +
" \"commitMessage\" : {" +
" \"summary\" : \"Delete foo.json\"" +
" }" +
'}';
final HttpHeaders headers = HttpHeaders.of(HttpMethod.POST, CONTENTS_PREFIX)
.contentType(MediaType.JSON);
final AggregatedHttpMessage res1 = httpClient().execute(headers, body).aggregate().join();
assertThat(res1.headers().status()).isEqualTo(HttpStatus.OK);
final AggregatedHttpMessage res2 = httpClient().get(CONTENTS_PREFIX + "/**").aggregate().join();
// /a directory and /a/bar.txt file are left
assertThat(Jackson.readTree(res2.content().toStringUtf8()).size()).isEqualTo(2);
}
内容来源于网络,如有侵权,请联系作者删除!