本文整理了Java中io.syndesis.core.Json.writer()
方法的一些代码示例,展示了Json.writer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.writer()
方法的具体详情如下:
包路径:io.syndesis.core.Json
类名称:Json
方法名:writer
暂无
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
public static String serializeJson(final JsonNode schemaNode) {
try {
return Json.writer().writeValueAsString(schemaNode);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize JSON schema", e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
public static String serialize(final Swagger swagger) {
try {
return Json.writer().writeValueAsString(swagger);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize Swagger specification", e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
private static JsonNode createSchemaFromModelImpl(final Model schema) {
try {
final String schemaString = Json.writer().writeValueAsString(schema);
return parseJsonSchema(schemaString);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
static String resolve(final String specification) throws Exception {
final String specificationToUse;
if (specification.toLowerCase(Locale.US).startsWith("http")) {
specificationToUse = RemoteUrl.urlToString(specification, null);
} else {
specificationToUse = specification;
}
final JsonNode node = convertToJson(specificationToUse);
return Json.writer().writeValueAsString(node);
}
代码示例来源:origin: io.syndesis.rest/rest-inspector
@Override
protected String fetchJsonFor(final String fullyQualifiedName, final Context<JsonNode> context) throws IOException {
final JsonNode classNode = findClassNode(fullyQualifiedName, context.getState());
final JsonNode javaClass = JsonNodeFactory.instance.objectNode().set("JavaClass", classNode);
return Json.writer().writeValueAsString(javaClass);
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
private static JsonNode createSchemaFromProperty(final String specification, final Property schema) {
if (schema instanceof MapProperty) {
try {
final String schemaString = Json.writer().writeValueAsString(schema);
return parseJsonSchema(schemaString);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize/read given JSON specification in response schema: " + schema, e);
}
} else if (schema instanceof StringProperty) {
return null;
}
final String reference = determineSchemaReference(schema);
final String title = Optional.ofNullable(schema.getTitle()).orElse(reference.replaceAll("^.*/", ""));
return createSchemaFromReference(specification, title, reference);
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
private static DataShape createShapeFromProperty(final String specification, final Property schema) {
if (schema instanceof MapProperty) {
try {
final String schemaString = Json.writer().writeValueAsString(schema);
return new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).specification(schemaString).build();
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e);
}
} else if (schema instanceof StringProperty) {
return DATA_SHAPE_NONE;
}
final String reference = determineSchemaReference(schema);
final String title = Optional.ofNullable(schema.getTitle()).orElse(reference.replaceAll("^.*/", ""));
return createShapeFromReference(specification, title, reference);
}
代码示例来源:origin: io.syndesis.rest/rest-jsondb
@Override
public void set(T entity) {
try {
String dbPath = getCollectionPath()+"/:"+entity.getId().get();
byte[] json = Json.writer().writeValueAsBytes(entity);
jsondb.set(dbPath, json);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-endpoint
try (ZipOutputStream tos = new ZipOutputStream(out) ) {
ModelExport exportObject = ModelExport.of(Schema.VERSION);
addEntry(tos, EXPORT_MODEL_INFO_FILE_NAME, Json.writer().writeValueAsBytes(exportObject));
addEntry(tos, EXPORT_MODEL_FILE_NAME, memJsonDB.getAsByteArray("/"));
memJsonDB.close();
代码示例来源:origin: io.syndesis.rest/rest-metrics-jsondb
/**
* Persists the latest metrics of a live pod to the database.
*/
@Override
public void persist(RawMetrics rawMetrics) {
try {
//persist the latest rawMetrics
String path = path(rawMetrics.getIntegrationId(), rawMetrics.getPod());
String json = Json.writer().writeValueAsString(rawMetrics);
if (jsonDB.exists(path)) {
//only update if not the same (don't cause unnecessary and expensive writes)
if (! jsonDB.getAsString(path).equals(json)) {
jsonDB.update(path, json);
}
} else {
jsonDB.set(path, json);
}
} catch (JsonProcessingException e) {
LOGGER.error("Error persisting metrics!", e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-jsondb
@Override
public T create(T entity) {
try {
String dbPath = getCollectionPath()+"/:"+entity.getId().get();
// Only create if it did not exist.
if( jsondb.exists(dbPath) ) {
return null;
}
byte[] json = Json.writer().writeValueAsBytes(entity);
jsondb.set(dbPath, json);
return entity;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-jsondb
@Override
public T update(T entity) {
try {
T previousValue = this.fetch(entity.getId().get());
// Only update if the entity existed.
if( previousValue !=null ) {
String dbPath = getCollectionPath()+"/:"+entity.getId().get();
byte[] json = Json.writer().writeValueAsBytes(entity);
jsondb.set(dbPath, json);
}
return previousValue;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-endpoint
@PATCH
@Path(value = "/{id}")
@Consumes(MediaType.APPLICATION_JSON)
default void patch(@NotNull @PathParam("id") @ApiParam(required = true) String id, @NotNull JsonNode patchJson) throws IOException {
Class<T> modelClass = resourceKind().getModelClass();
final T existing = getDataManager().fetch(modelClass, id);
if( existing == null ) {
throw new EntityNotFoundException();
}
JsonNode document = Json.reader().readTree(Json.writer().writeValueAsString(existing));
// Attempt to apply the patch...
final JsonMergePatch patch;
try {
patch = JsonMergePatch.fromJson(patchJson);
document = patch.apply(document);
} catch (JsonPatchException e) {
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
// Convert the Json back to an entity.
T obj = Json.reader().forType(modelClass).readValue(Json.writer().writeValueAsBytes(document));
if (this instanceof Validating) {
final Validator validator = ((Validating<?>) this).getValidator();
final Set<ConstraintViolation<T>> violations = validator.validate(obj, AllValidations.class);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
getDataManager().update(obj);
}
代码示例来源:origin: io.syndesis.rest/rest-metrics-jsondb
.lastProcessed(Optional.ofNullable(lastProcessed))
.build();
String json = Json.writer().writeValueAsString(updatedHistoryMetrics);
jsonDB.update(path(integrationId,historyKey), json);
} else {
String json = Json.writer().writeValueAsString(metrics.get(entry.getKey()));
jsonDB.set(path(integrationId,historyKey), json);
代码示例来源:origin: io.syndesis.rest/rest-metrics-jsondb
@Test
public void testDeadPodCurator() throws IOException, ParseException {
String integrationId = "intId1";
MetricsCollector collector = new MetricsCollector(null, jsondb, null);
//Update pod1 metrics and kill pod1
Set<String> livePodIds = new HashSet<String>(
Arrays.asList("pod2", "pod3", "pod4", "pod5"));
jsondb.update(JsonDBRawMetrics.path("intId1","pod1"), Json.writer().writeValueAsString(raw("intId1","1","pod1",12L,"31-01-2018 10:22:56")));
Map<String,RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId);
IntegrationMetricsSummary summary = intMH
.compute(integrationId, metrics, livePodIds);
assertThat(summary.getMessages()).isEqualTo(18);
assertThat(summary.getErrors()).isEqualTo(3);
//Oldest living pod is now pod2
assertThat(summary.getStart().get()).isEqualTo(sdf.parse("31-01-2018 10:22:56"));
collector.close();
}
代码示例来源:origin: io.syndesis.rest/rest-metrics-jsondb
@Test
public void testGetIntegrationSummary() throws IOException, ParseException {
String integrationId = "intId1";
Set<String> livePodIds = new HashSet<String>(
Arrays.asList("pod1", "pod2", "pod3", "pod4", "pod5"));
MetricsCollector collector = new MetricsCollector(null, jsondb, null);
Map<String,RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId);
IntegrationMetricsSummary summary = intMH
.compute(integrationId, metrics, livePodIds);
assertThat(summary.getMessages()).isEqualTo(9);
assertThat(summary.getErrors()).isEqualTo(3);
//Oldest living pod
assertThat(summary.getStart().get()).isEqualTo(sdf.parse("31-01-2018 10:20:56"));
//Update pod2, add 6 messages
jsondb.update(JsonDBRawMetrics.path("intId1","pod2"), Json.writer().writeValueAsString(raw("intId1","2","pod2",9L,"31-01-2018 10:22:56")));
Map<String,RawMetrics> updatedMetrics = jsondbRM.getRawMetrics(integrationId);
IntegrationMetricsSummary updatedSummary = intMH
.compute(integrationId, updatedMetrics, livePodIds);
assertThat(updatedSummary.getMessages()).isEqualTo(15);
assertThat(updatedSummary.getErrors()).isEqualTo(3);
collector.close();
}
代码示例来源:origin: io.syndesis.rest/rest-dao
@Test
public void deserializeModelDataTest() throws IOException {
Integration integrationIn = new Integration.Builder()
.tags(new TreeSet<>(Arrays.asList("tag1", "tag2")))
.createdAt(System.currentTimeMillis())
.build();
String integrationJson = Json.writer().writeValueAsString(integrationIn);
// System.out.println(integrationJson);
Integration integrationOut = Json.reader().forType(Integration.class).readValue(integrationJson);
//serialize
ConnectorGroup cg = new ConnectorGroup.Builder().id("label").name("label").build();
ModelData<ConnectorGroup> mdIn = new ModelData<>(Kind.ConnectorGroup, cg);
Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdIn.getDataAsJson());
//deserialize
String json = Json.writer().writeValueAsString(mdIn);
ModelData<?> mdOut = Json.reader().forType(ModelData.class).readValue(json);
Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdOut.getDataAsJson());
}
内容来源于网络,如有侵权,请联系作者删除!