本文整理了Java中com.linecorp.centraldogma.internal.Jackson.writeValueAsString()
方法的一些代码示例,展示了Jackson.writeValueAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jackson.writeValueAsString()
方法的具体详情如下:
包路径:com.linecorp.centraldogma.internal.Jackson
类名称:Jackson
方法名:writeValueAsString
暂无
代码示例来源: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: line/centraldogma
@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-common
@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: line/centraldogma
/**
* Returns the textual representation of the specified content.
*
* @throws IllegalStateException if the content is {@code null}
*/
default String contentAsText() {
final T content = content();
if (content instanceof JsonNode) {
try {
return Jackson.writeValueAsString(content);
} catch (JsonProcessingException e) {
// Should never happen because it's a JSON tree already.
throw new Error(e);
}
} else {
return content.toString();
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* Returns the textual representation of the specified content.
*
* @throws IllegalStateException if the content is {@code null}
*/
default String contentAsText() {
final T content = content();
if (content instanceof JsonNode) {
try {
return Jackson.writeValueAsString(content);
} catch (JsonProcessingException e) {
// Should never happen because it's a JSON tree already.
throw new Error(e);
}
} else {
return content.toString();
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
/**
* Returns the textual representation of {@link #content()}.
*
* @throws IllegalStateException if this {@link Entry} is a directory
*/
public String contentAsText() {
ensureContent();
if (contentAsText == null) {
if (content instanceof JsonNode) {
try {
contentAsText = Jackson.writeValueAsString(content);
} catch (JsonProcessingException e) {
// Should never happen because it's a JSON tree already.
throw new Error(e);
}
} else {
contentAsText = content.toString();
}
}
return contentAsText;
}
代码示例来源:origin: line/centraldogma
public static Entry convert(com.linecorp.centraldogma.common.Entry<?> entry) {
final Entry file = new Entry(entry.path(), convertEntryType(entry.type()));
switch (entry.type()) {
case JSON:
// FIXME(trustin): Inefficiency
try {
file.setContent(Jackson.writeValueAsString(entry.content()));
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
break;
case TEXT:
file.setContent((String) entry.content());
break;
case DIRECTORY:
break;
default:
throw new IllegalArgumentException("unsupported entry type: " + entry.type());
}
return file;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-legacy-shaded
public static Entry convert(com.linecorp.centraldogma.common.Entry<?> entry) {
final Entry file = new Entry(entry.path(), convertEntryType(entry.type()));
switch (entry.type()) {
case JSON:
// FIXME(trustin): Inefficiency
try {
file.setContent(Jackson.writeValueAsString(entry.content()));
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
break;
case TEXT:
file.setContent((String) entry.content());
break;
case DIRECTORY:
break;
default:
throw new IllegalArgumentException("unsupported entry type: " + entry.type());
}
return file;
}
代码示例来源: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: com.linecorp.centraldogma/centraldogma-common-legacy-shaded
@Override
protected Change doForward(com.linecorp.centraldogma.common.Change<?> value) {
final Change change = new Change(value.path(), convertChangeType(value.type()));
switch (change.getType()) {
case UPSERT_JSON:
case APPLY_JSON_PATCH:
try {
change.setContent(Jackson.writeValueAsString(value.content()));
} catch (JsonProcessingException e) {
throw new ChangeFormatException("failed to read a JSON tree", e);
}
break;
case UPSERT_TEXT:
case APPLY_TEXT_PATCH:
case RENAME:
change.setContent((String) value.content());
break;
case REMOVE:
break;
}
return change;
}
代码示例来源:origin: line/centraldogma
@Override
protected Change doForward(com.linecorp.centraldogma.common.Change<?> value) {
final Change change = new Change(value.path(), convertChangeType(value.type()));
switch (change.getType()) {
case UPSERT_JSON:
case APPLY_JSON_PATCH:
try {
change.setContent(Jackson.writeValueAsString(value.content()));
} catch (JsonProcessingException e) {
throw new ChangeFormatException("failed to read a JSON tree", e);
}
break;
case UPSERT_TEXT:
case APPLY_TEXT_PATCH:
case RENAME:
change.setContent((String) value.content());
break;
case REMOVE:
break;
}
return change;
}
代码示例来源:origin: line/centraldogma
'}');
final ProjectMetadata obj = Jackson.readValue(Jackson.writeValueAsString(metadata),
ProjectMetadata.class);
assertThat(obj.name()).isEqualTo("test");
assertThat(obj.repos().size()).isOne();
assertThat(obj.members().size()).isOne();
assertThatJson(Jackson.writeValueAsString(obj.members().get("armeria@dogma.org")))
.isEqualTo(Jackson.writeValueAsString(member));
assertThat(obj.tokens().size()).isOne();
assertThat(obj.creation()).isNotNull();
代码示例来源:origin: line/centraldogma
'}');
final ProjectMetadata obj = Jackson.readValue(Jackson.writeValueAsString(metadata),
ProjectMetadata.class);
assertThat(obj.name()).isEqualTo("test");
内容来源于网络,如有侵权,请联系作者删除!