io.syndesis.common.util.Json.writer()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中io.syndesis.common.util.Json.writer()方法的一些代码示例,展示了Json.writer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.writer()方法的具体详情如下:
包路径:io.syndesis.common.util.Json
类名称:Json
方法名:writer

Json.writer介绍

[英]Returns an immutable and thread-safe instance of an ObjectWriter, used for object serialization
[中]返回ObjectWriter的不可变且线程安全的实例,用于对象序列化

代码示例

代码示例来源:origin: io.syndesis.server/server-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.server/server-api-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.server/server-api-generator

public static String serialize(final Swagger swagger) {
  try {
    return Json.writer().writeValueAsString(swagger);
  } catch (final JsonProcessingException e) {
    throw new IllegalStateException("Unable to serialize OpenAPI specification", e);
  }
}

代码示例来源:origin: io.syndesis.server/server-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 OpenAPI specification", e);
  }
}

代码示例来源:origin: io.syndesis.common/common-util

public static String toString(Object value) {
  try {
    return writer().writeValueAsString(value);
  } catch (JsonProcessingException e) {
    throw new SyndesisServerException(e);
  }
}

代码示例来源:origin: io.syndesis.common/common-model

@JsonRawValue
@JsonProperty("data")
public String getDataAsJson() throws JsonProcessingException {
  if (json == null) {
    json = Json.writer().writeValueAsString(data);
  }
  return json;
}

代码示例来源:origin: io.syndesis.common/common-model

@JsonIgnore
default String toJson() {
  try {
    return Json.writer().writeValueAsString(this);
  } catch (JsonProcessingException e) {
    throw new JsonProcessingRuntimeException(e);
  }
}

代码示例来源:origin: io.syndesis.common/common-model

@JsonRawValue
@JsonProperty("data")
public void setDataFromJson(JsonNode json) throws JsonProcessingException {
  this.data = null;
  this.json = Json.writer().writeValueAsString(json);
}

代码示例来源:origin: io.syndesis.server/server-api-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.server/server-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.server/server-endpoint

private static String serialize(final Mixed value) {
    try {
      return Json.writer().writeValueAsString(value);
    } catch (final JsonProcessingException e) {
      throw new AssertionError(e);
    }
  }
}

代码示例来源:origin: io.syndesis.extension/extension-converter

private Extension unmarshal(JsonNode node) throws IOException {
  byte[] bytes = Json.writer().writeValueAsBytes(node);
  return Json.reader().forType(Extension.class).readValue(bytes);
}

代码示例来源:origin: io.syndesis.extension/extension-converter

private ObjectNode marshal(Extension extension) throws IOException {
  byte[] bytes = Json.writer().writeValueAsBytes(extension);
  return Json.reader().forType(ObjectNode.class).readValue(bytes);
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

private static ObjectNode createSchemaFromProperty(final ObjectNode json, final String name, final Property schema) {
  if (schema instanceof MapProperty || schema instanceof ObjectProperty) {
    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 = determineTitleOf(name, schema);
  return resolveSchemaForReference(json, title, reference);
}

代码示例来源:origin: io.syndesis.server/server-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.server/server-connector-generator

@Override
public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) {
  final Optional<Response> maybeResponse = findResponse(operation);
  if (!maybeResponse.isPresent()) {
    return DATA_SHAPE_NONE;
  }
  final Response response = maybeResponse.get();
  final Model responseSchema = response.getResponseSchema();
  final String description = response.getDescription();
  final JsonNode schema = createSchemaFromModel(json, description, responseSchema);
  String schemaString;
  try {
    schemaString = Json.writer().writeValueAsString(schema);
  } catch (final JsonProcessingException e) {
    throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e);
  }
  return new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).name("Response").description("API response payload")
    .specification(schemaString).build();
}

代码示例来源:origin: io.syndesis.connector/connector-support-processor

@Test
public void testCases() throws Exception {
  String schemaStr = Json.writer().forType(JsonSchema.class).writeValueAsString(schema);
  JsonNode schemaNode = Json.reader().forType(JsonNode.class).readTree(schemaStr);
  final HttpRequestWrapperProcessor processor = new HttpRequestWrapperProcessor(schemaNode);
  final Exchange exchange = mock(Exchange.class);
  final Message message = mock(Message.class);
  final CamelContext camelContext = mock(CamelContext.class);
  when(camelContext.getHeadersMapFactory()).thenReturn(mock(HeadersMapFactory.class));
  when(exchange.getIn()).thenReturn(message);
  when(exchange.getContext()).thenReturn(camelContext);
  when(message.getBody()).thenReturn(givenBody);
  when(message.getHeader("param1", String.class)).thenReturn("param_value1");
  when(message.getHeader("param2", String.class)).thenReturn("param_value2");
  processor.process(exchange);
  final ArgumentCaptor<Message> replacement = ArgumentCaptor.forClass(Message.class);
  verify(exchange).setIn(replacement.capture());
  assertThat(replacement.getValue().getBody()).isEqualTo(replacedBody);
}

代码示例来源:origin: io.syndesis.connector/connector-sql

@Test
public void adaptForSqlNoParamTest() throws IOException, JSONException {
  CamelContext camelContext = new DefaultCamelContext();
  SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension(camelContext);
  Map<String,Object> parameters = new HashMap<>();
  for (final String name: properties.stringPropertyNames()) {
    parameters.put(name.substring(name.indexOf('.') + 1), properties.getProperty(name));
  }
  parameters.put("query", "SELECT * FROM NAME");
  Optional<MetaData> metadata = ext.meta(parameters);
  SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
  SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-connector", parameters, metadata.get());
  String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_no_param_metadata.json"), StandardCharsets.UTF_8).trim();
  ObjectWriter writer = Json.writer();
  String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
  assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}

代码示例来源:origin: io.syndesis.connector/connector-sql

@Test
public void adaptForSqlTest() throws IOException, JSONException {
  CamelContext camelContext = new DefaultCamelContext();
  SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension(camelContext);
  Map<String,Object> parameters = new HashMap<>();
  for (final String name: properties.stringPropertyNames()) {
    parameters.put(name.substring(name.indexOf('.') + 1), properties.getProperty(name));
  }
  parameters.put("query", "SELECT * FROM NAME WHERE ID=:#id");
  Optional<MetaData> metadata = ext.meta(parameters);
  SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
  SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-connector", parameters, metadata.get());
  String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_metadata.json"), StandardCharsets.UTF_8).trim();
  ObjectWriter writer = Json.writer();
  String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
  assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}

代码示例来源:origin: io.syndesis.server/server-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();
}

相关文章