本文整理了Java中io.syndesis.core.Json.reader()
方法的一些代码示例,展示了Json.reader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.reader()
方法的具体详情如下:
包路径:io.syndesis.core.Json
类名称:Json
方法名:reader
暂无
代码示例来源: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.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-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-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-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-metrics-jsondb
/**
* Obtains all RawMetrics entries in the DB for the current integration
*
* @param integrationId - the integrationId for which we are obtaining the metrics
* @return a Map containing all RawMetrics entries for the current integration,
* the key is either HISTORY or the podName.
* @throws IOException
*/
@Override
public Map<String,RawMetrics> getRawMetrics(String integrationId) throws IOException {
//try to obtain all raw metrics in this integration
Map<String,RawMetrics> metrics = new HashMap<>();
String path = path(integrationId);
String json = jsonDB.getAsString(path);
if (json != null) {
metrics = Json.reader().forType(VALUE_TYPE_REF).readValue(json);
}
return metrics;
}
代码示例来源:origin: io.syndesis.rest/rest-inspector
@SuppressWarnings("PMD.CyclomaticComplexity")
protected final List<String> getPathsFromJavaClassJson(final String prefix, final String specification, final Context<T> context) {
try {
final JsonNode node = Json.reader().readTree(specification);
if (node == null) {
return Collections.emptyList();
代码示例来源:origin: io.syndesis.rest/rest-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.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-jsondb
@Override
public T fetch(String id) {
try {
String dbPath = getCollectionPath()+"/:"+id;
byte[] json = jsondb.getAsByteArray(dbPath);
if( json==null || json.length == 0 ) {
return null;
}
return Json.reader().forType(getType()).readValue(json);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
代码示例来源:origin: io.syndesis.rest/rest-endpoint
modelExport = Json.reader().forType(ModelExport.class).readValue(zis);
代码示例来源:origin: io.syndesis.rest/rest-metrics-jsondb
/**
* If Integrations get deleted we should also delete their metrics
*
* @param activeIntegrationIds
* @throws IOException
* @throws JsonMappingException
*/
@Override
public void curate(Set<String> activeIntegrationIds) throws IOException, JsonMappingException {
//1. Loop over all RawMetrics
String json = jsonDB.getAsString(path(), new GetOptions().depth(1));
if (json != null) {
Map<String,Boolean> metricsMap = Json.reader().forType(TYPE_REFERENCE).readValue(json);
Set<String> rawIntegrationIds = metricsMap.keySet();
for (String rawIntId : rawIntegrationIds) {
if (! activeIntegrationIds.contains(rawIntId)) {
jsonDB.delete(path(rawIntId));
}
}
}
}
代码示例来源: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
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.rest/rest-metrics-jsondb
@Test
public void testGetMetricsForIntegration1() throws IOException {
String json = jsondb.getAsString(JsonDBRawMetrics.path("intId1"), new GetOptions().prettyPrint(true));
Map<String,RawMetrics> metrics = Json.reader().forType(new TypeReference<Map<String,RawMetrics>>() {}).readValue(json);
assertThat(metrics.size()).isEqualTo(3);
assertThat(metrics.keySet()).contains("HISTORY1");
}
代码示例来源:origin: io.syndesis.rest/rest-jsondb
ObjectReader reader = Json.reader();
TypeFactory typeFactory = reader.getTypeFactory();
MapType mapType = typeFactory.constructMapType(LinkedHashMap.class, String.class, getType());
代码示例来源: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.rest/rest-inspector
@Test
public void shouldFindNestedClassesWithinFullJson() throws IOException, JSONException {
final SpecificationClassInspector inspector = new SpecificationClassInspector();
final String specification = read("/twitter4j.Status.full.json");
final Context<JsonNode> context = new Context<>(Json.reader().readTree(specification));
final String json = inspector.fetchJsonFor("twitter4j.GeoLocation", context);
assertEquals(json, read("/twitter4j.GeoLocation.json"), JSONCompareMode.STRICT);
}
内容来源于网络,如有侵权,请联系作者删除!