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

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

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

Json.reader介绍

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

代码示例

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

private static Map<String, String> readJsonMap(String params) {
  try {
    return Json.reader().forType(MAP_TYPE).readValue(params);
  } catch (IOException e) {
    throw new ExceptionInInitializerError(e);
  }
}

代码示例来源:origin: io.syndesis.integration/integration-runtime

private List<FilterRule> extractRules(String rulesString) {
  try {
    if (rulesString == null || rulesString.isEmpty()) {
      return null;
    }
    return Json.reader().forType(new TypeReference<List<FilterRule>>(){}).readValue(rulesString);
  } catch (IOException e) {
    throw new IllegalStateException(String.format("Cannot deserialize %s: %s", rulesString, e.getMessage()),e);
  }
}

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

@Override
public Optional<Connector> loadConnector(String id) {
  Connector connector = null;
  try (InputStream is = ConnectorTestSupport.class.getClassLoader().getResourceAsStream("META-INF/syndesis/connector/" + id + ".json")) {
    connector = Json.reader().forType(Connector.class).readValue(is);
  } catch (IOException e) {
    Assertions.fail("Unable to load connector: " + id, e);
  }
  return Optional.ofNullable(connector);
}

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

static JsonNode convertToJson(final String specification) throws IOException, JsonProcessingException {
  final JsonNode specRoot;
  if (JSON_TEST.matcher(specification).matches()) {
    specRoot = Json.reader().readTree(specification);
  } else {
    specRoot = Json.convertValue(YAML_PARSER.load(specification), JsonNode.class);
  }
  return specRoot;
}

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

static JsonNode convertToJson(final String specification) throws IOException, JsonProcessingException {
  final JsonNode specRoot;
  if (specification.matches("\\s+\\{")) {
    specRoot = Json.reader().readTree(specification);
  } else {
    specRoot = Json.convertValue(YAML_PARSER.load(specification), JsonNode.class);
  }
  return specRoot;
}

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

private static ObjectNode parseJsonSchema(final String schema) {
  try {
    return (ObjectNode) Json.reader().readTree(schema);
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to parse given JSON schema: " + StringUtils.abbreviate(schema, 100), e);
  }
}

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

@JsonIgnore
public T getData() throws IOException {
  if (data == null && kind != null && json != null) {
    @SuppressWarnings("unchecked")
    final Class<T> modelClass = (Class<T>) kind.getModelClass();
    data = Json.reader().forType(modelClass).readValue(json);
  }
  return data;
}

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

private Extension doGetExtension(InputStream binaryExtension) throws IOException {
  Optional<InputStream> entry = readPath(binaryExtension, MANIFEST_LOCATION);
  if (!entry.isPresent()) {
    throw new IllegalArgumentException("Cannot find manifest file (" + MANIFEST_LOCATION + ") inside JAR");
  }
  JsonNode tree = Json.reader().readTree(entry.get());
  Extension extension = ExtensionConverter.getDefault().toInternalExtension(tree);
  if (extension == null) {
    throw new IllegalArgumentException("Cannot extract Extension from manifest file (" + MANIFEST_LOCATION + ") inside JAR");
  }
  return extension;
}

代码示例来源:origin: io.syndesis.integration/integration-runtime

protected Integration loadIntegration() throws IOException {
  final Integration integration;
  try (InputStream is = ResourceHelper.resolveResourceAsInputStream(getContext().getClassResolver(), configurationUri)) {
    if (is != null) {
      LOGGER.info("Loading integration from: {}", configurationUri);
      integration = Json.reader().forType(Integration.class).readValue(is);
    } else {
      throw new IllegalStateException("Unable to load deployment: " + configurationUri);
    }
  }
  return integration;
}

代码示例来源: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-api-generator

@Value.Lazy
default ObjectNode getResolvedJsonGraph() {
  try {
    final ObjectNode json = (ObjectNode) Json.reader().readTree(getResolvedSpecification());
    return JsonSchemaHelper.resolvableNodeForSpecification(json);
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to parse OpenAPI specification resolved as JSON", e);
  }
}

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

@Value.Lazy
default ObjectNode getResolvedJsonGraph() {
  try {
    final ObjectNode json = (ObjectNode) Json.reader().readTree(getResolvedSpecification());
    return JsonSchemaHelper.resolvableNodeForSpecification(json);
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to parse OpenAPI specification resolved as JSON", e);
  }
}

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

@SuppressWarnings({ "PMD.UnusedLocalVariable"})
  @Test
  public void verifyJacksonBehaviorWithSourceStreams() throws IOException {
    ClassLoader classLoader = getClass().getClassLoader();
    // disabling feature inline, skipt closing source stream
    try(InputStream fis = spy(new FileInputStream(new File(classLoader.getResource("model.json").getFile())))){
      ModelExport models = Json.reader().forType(ModelExport.class).readValue(fis);
      verify(fis, times(0)).close();
    }
  }
}

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

static String reformatJson(final String json) throws IOException {
  if (json == null) {
    return null;
  }
  final Map<?, ?> tree = Json.reader().forType(Map.class).readValue(json);
  return Json.copyObjectMapperConfiguration().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
    .writerWithDefaultPrettyPrinter().writeValueAsString(tree);
}

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

static String reformatJson(final String json) throws IOException {
  if (json == null) {
    return null;
  }
  final Map<?, ?> tree = Json.reader().forType(Map.class).readValue(json);
  return Json.copyObjectMapperConfiguration().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
    .writerWithDefaultPrettyPrinter().writeValueAsString(tree);
}

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

public UnifiedXmlDataShapeGeneratorRequestShapeTest() throws IOException {
  final String specification;
  try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/petstore.swagger.json")) {
    specification = IOUtils.toString(in, StandardCharsets.UTF_8);
  }
  json = (ObjectNode) Json.reader().readTree(specification);
  final SwaggerParser parser = new SwaggerParser();
  swagger = parser.parse(specification);
}

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

public UnifiedXmlDataShapeGeneratorRequestShapeTest() throws IOException {
  final String specification;
  try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/petstore.swagger.json")) {
    specification = IOUtils.toString(in, StandardCharsets.UTF_8);
  }
  json = (ObjectNode) Json.reader().readTree(specification);
  final SwaggerParser parser = new SwaggerParser();
  swagger = parser.parse(specification);
}

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

public BaseSwaggerGeneratorExampleTest(final String connectorQualifier, final String name) throws IOException {
  specification = resource("/swagger/" + name + ".swagger.json", "/swagger/" + name + ".swagger.yaml");
  expected = Json.reader().forType(Connector.class)
    .readValue(resource("/swagger/" + name + "." + connectorQualifier + "_connector.json"));
}

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

@Test
public void shouldAdaptObjectMetadataForSchema() throws IOException {
  final Map<String, Object> properties = new HashMap<>();
  properties.put("sObjectName", "SimpleObject");
  final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties,
    MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
  assertThat(metadata.inputShape).isSameAs(metadata.inputShape);
  final Object oneOf = payload.getOneOf().iterator().next();
  final ObjectSchema inSchema = Json.reader().forType(ObjectSchema.class).readValue(metadata.inputShape.getSpecification()    );
  assertThat(inSchema).isEqualTo(oneOf);
  assertThat(inSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4);
}

相关文章