本文整理了Java中com.linecorp.centraldogma.internal.Jackson
类的一些代码示例,展示了Jackson
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jackson
类的具体详情如下:
包路径:com.linecorp.centraldogma.internal.Jackson
类名称:Jackson
暂无
代码示例来源: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
/**
* Creates a new instance from the given configuration file.
*
* @throws IOException if failed to load the configuration from the specified file
*/
public static CentralDogma forConfig(File configFile) throws IOException {
requireNonNull(configFile, "configFile");
return new CentralDogma(Jackson.readValue(configFile, CentralDogmaConfig.class));
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
@Override
public String toString() {
try {
return Jackson.writeValueAsPrettyString(this);
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
}
代码示例来源: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: com.linecorp.centraldogma/centraldogma-common
/**
* Returns the value converted from the JSON representation of the specified content.
*
* @return the value converted from the content
*
* @throws IllegalStateException if the content is {@code null}
* @throws JsonParseException if failed to parse the content as JSON
* @throws JsonMappingException if failed to convert the parsed JSON into {@code valueType}
*/
default <U> U contentAsJson(Class<U> valueType) throws JsonParseException, JsonMappingException {
final T content = content();
if (content instanceof TreeNode) {
return Jackson.treeToValue((TreeNode) content, valueType);
}
return Jackson.readValue(contentAsText(), valueType);
}
}
代码示例来源: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
/**
* Converts this patch into JSON.
*/
public ArrayNode toJson() {
return (ArrayNode) Jackson.valueToTree(this);
}
代码示例来源:origin: line/centraldogma
@Test
public void testTimeSerialization() throws IOException {
final Member member =
new Member("armeria@dogma.org", ProjectRole.MEMBER, newCreationTag());
assertThatJson(member).isEqualTo("{\n" +
" \"login\" : \"armeria@dogma.org\",\n" +
" \"role\" : \"MEMBER\",\n" +
" \"creation\" : {\n" +
" \"user\" : \"editor@dogma.org\",\n" +
" \"timestamp\" : \"2017-01-01T00:00:00Z\"\n" +
" }\n" +
'}');
final Member obj = Jackson.readValue(Jackson.writeValueAsString(member),
Member.class);
assertThat(obj.login()).isEqualTo("armeria@dogma.org");
assertThat(obj.role()).isEqualTo(ProjectRole.MEMBER);
assertThat(obj.creation()).isNotNull();
assertThat(obj.creation().user()).isEqualTo("editor@dogma.org");
assertThat(obj.creation().timestamp()).isEqualTo("2017-01-01T00:00:00Z");
}
代码示例来源:origin: line/centraldogma
/**
* Returns a properties object which is converted to {@code T}.
*/
@Nullable
public <T> T properties(Class<T> clazz) throws JsonProcessingException {
return properties != null ? Jackson.treeToValue(properties, clazz) : null;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
@Override
@Nullable
public String contentAsText() {
if (content == null) {
return null;
}
if (content instanceof CharSequence) {
return content.toString();
}
if (content instanceof JsonNode) {
try {
return Jackson.writeValueAsString(content);
} catch (JsonProcessingException e) {
// Should never reach here.
throw new Error(e);
}
}
throw new Error();
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
@Override
public HttpResponse convertResponse(ServiceRequestContext ctx, Object resObj) throws Exception {
try {
if (resObj instanceof HolderWithLocation) {
return handleWithLocation((HolderWithLocation<?>) resObj);
}
final JsonNode jsonNode = Jackson.valueToTree(resObj);
final String url = jsonNode.get("url").asText();
// Remove the url field and send it with the LOCATION header.
((ObjectNode) jsonNode).remove("url");
final HttpHeaders headers = HttpHeaders.of(HttpStatus.CREATED)
.add(HttpHeaderNames.LOCATION, url)
.contentType(MediaType.JSON_UTF_8);
return HttpResponse.of(headers, HttpData.of(Jackson.writeValueAsBytes(jsonNode)));
} catch (JsonProcessingException e) {
logger.debug("Failed to convert a response:", e);
return HttpApiUtil.newResponse(HttpStatus.INTERNAL_SERVER_ERROR, e);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
private static ObjectId newBlob(ObjectInserter inserter, JsonNode content) {
try {
return newBlob(inserter, Jackson.writeValueAsBytes(content));
} catch (IOException e) {
throw new StorageException("failed to serialize a JSON value: " + content, e);
}
}
代码示例来源:origin: line/centraldogma
result = Jackson.mergeTree(jsonNodes);
final List<String> expressions = query.expressions();
if (!Iterables.isEmpty(expressions)) {
result = Jackson.extractTree(result, expressions);
代码示例来源:origin: line/centraldogma
public static JsonNode extractTree(JsonNode jsonNode, Iterable<String> jsonPaths) {
for (String jsonPath : jsonPaths) {
jsonNode = extractTree(jsonNode, jsonPath);
}
return jsonNode;
}
代码示例来源:origin: line/centraldogma
public static JsonNode mergeTree(JsonNode... jsonNodes) {
return mergeTree(ImmutableList.copyOf(requireNonNull(jsonNodes, "jsonNodes")));
}
代码示例来源:origin: line/centraldogma
@Test
public void nullCanBeAnyTypeWhileMerging() throws IOException {
final JsonNode nullNode = readTree("{\"a\": null}");
final JsonNode numberNode = readTree("{\"a\": 1}");
JsonNode merged = Jackson.mergeTree(nullNode, numberNode);
assertThatJson(merged).isEqualTo("{\"a\": 1}");
final JsonNode stringNode = readTree("{\"a\": \"foo\"}");
merged = Jackson.mergeTree(nullNode, stringNode);
assertThatJson(merged).isEqualTo("{\"a\": \"foo\"}");
final JsonNode arrayNode = readTree("{\"a\": [1, 2, 3]}");
merged = Jackson.mergeTree(nullNode, arrayNode);
assertThatJson(merged).isEqualTo("{\"a\": [1, 2, 3]}");
final JsonNode objectNode = readTree('{' +
" \"a\": {" +
" \"b\": \"foo\"" +
" }" +
'}');
merged = Jackson.mergeTree(nullNode, objectNode);
assertThatJson(merged).isEqualTo('{' +
" \"a\": {" +
" \"b\": \"foo\"" +
" }" +
'}');
}
代码示例来源: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
/**
* Converts this patch into JSON.
*/
public ArrayNode toJson() {
return (ArrayNode) Jackson.valueToTree(this);
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
/**
* Returns the value converted from the JSON representation of {@link #content()}.
*
* @return the value converted from {@link #content()}
*
* @throws IllegalStateException if this {@link Entry} is a directory
* @throws JsonParseException if failed to parse the {@link #content()} as JSON
* @throws JsonMappingException if failed to convert the parsed JSON into {@code valueType}
*/
public <U> U contentAsJson(Class<U> valueType) throws JsonParseException, JsonMappingException {
final T content = content();
if (content instanceof TreeNode) {
return Jackson.treeToValue((TreeNode) content, valueType);
}
return Jackson.readValue(contentAsText(), valueType);
}
代码示例来源:origin: line/centraldogma
'}');
final ProjectMetadata obj = Jackson.readValue(Jackson.writeValueAsString(metadata),
ProjectMetadata.class);
assertThat(obj.name()).isEqualTo("test");
内容来源于网络,如有侵权,请联系作者删除!