io.syndesis.core.Json类的使用及代码示例

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

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

Json介绍

暂无

代码示例

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

public static String serializeJson(final ObjectNode schemaNode) {
  try {
    return Json.mapper().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-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-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.rest/rest-connector-generator

private static ConnectorTemplate fetchSwaggerConnectorTemplateFromDeployment() {
    final Configuration configuration = Configuration.builder()//
      .jsonProvider(new JacksonJsonProvider(Json.copyObjectMapperConfiguration()))//
      .mappingProvider(new JacksonMappingProvider(Json.copyObjectMapperConfiguration()))//
      .build();

    final List<ConnectorTemplate> templates = JsonPath.using(configuration)
      .parse(AbstractSwaggerConnectorTest.class.getResourceAsStream("/io/syndesis/dao/deployment.json"))
      .read("$..[?(@['id'] == 'swagger-connector-template')]", new TypeRef<List<ConnectorTemplate>>() {
        // type token pattern
      });

    return templates.get(0);
  }
}

代码示例来源: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());
  }

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

private ObjectNode marshal(Extension extension) {
  return Json.mapper().convertValue(extension, ObjectNode.class);
}

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

private static JsonNode parseJsonSchema(final String schema) {
  try {
    return 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.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/extension-converter

private Extension unmarshal(JsonNode node) {
  return Json.mapper().convertValue(node, Extension.class);
}

代码示例来源:origin: io.syndesis.rest/rest-inspector

@Override
protected Context<JsonNode> createContext(final String kind, final String type, final String specification,
  final Optional<byte[]> exemplar) {
  try {
    return new Context<>(Json.reader().readTree(specification));
  } catch (final IOException e) {
    throw new IllegalArgumentException("Unable to parse 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/connector-generator

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

代码示例来源:origin: io.syndesis.rest/rest-jsondb

@Override
public Set<String> fetchIds() {
  try {
    String json = jsondb.getAsString(getCollectionPath(), new GetOptions().depth(1));
    if (json != null) {
      Map<String,Boolean> map = Json.reader().forType(new TypeReference<Map<String,Boolean>>() {}).readValue(json);
      return map.keySet()
         .stream().map(path -> path.substring(path.indexOf(':') + 1)).collect(Collectors.toSet());
    } else {
      return Collections.<String>emptySet();
    }
  } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
    throw SyndesisServerException.launderThrowable(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/connector-generator

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

代码示例来源:origin: io.syndesis.rest/rest-controller

private EventBus.Subscription getChangeEventSubscription() {
  return (event, data) -> {
    // Never do anything that could block in this callback!
    if (event!=null && "change-event".equals(event)) {
      try {
        ChangeEvent changeEvent = Json.reader().forType(ChangeEvent.class).readValue(data);
        if (changeEvent != null) {
          changeEvent.getId().ifPresent(id -> {
            changeEvent.getKind()
                  .map(Kind::from)
                  .filter(k -> k == Kind.IntegrationDeployment)
                  .ifPresent(k -> {
                    checkIntegrationStatusIfNotAlreadyInProgress(id);
                  });
          });
        }
      } catch (IOException e) {
        LOG.error("Error while subscribing to change-event {}", data, e);
      }
    }
  };
}

代码示例来源: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/db-logging

private <T> T dbGet(Class<T> type, String path, GetOptions options) throws IOException {
  byte[] data = jsonDB.getAsByteArray(path, options);
  if (data == null) {
    return null;
  }
  return Json.mapper().readValue(data, type);
}

相关文章