本文整理了Java中io.syndesis.common.util.Json
类的一些代码示例,展示了Json
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json
类的具体详情如下:
包路径:io.syndesis.common.util.Json
类名称:Json
[英]JSON helper class.
[中]JSON助手类。
代码示例来源: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.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.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
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
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
final ObjectNode json = Json.convertValue(swagger, ObjectNode.class);
json.remove(Arrays.asList("info", "tags", "definitions", "externalDocs"));
return Json.writer().writeValueAsString(json);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize minified OpenAPI specification", e);
代码示例来源:origin: io.syndesis.connector/connector-support-processor
@Override
public void process(Exchange exchange) throws Exception {
final Message message = exchange.getIn();
final Object body = message.getBody();
final ObjectNode rootNode = Json.copyObjectMapperConfiguration().createObjectNode();
if (!parameters.isEmpty()) {
final ObjectNode parametersNode = rootNode.putObject("parameters");
for (String parameter : parameters) {
parametersNode.put(parameter, message.getHeader(parameter, String.class));
}
}
if (body instanceof String) {
final String string = (String) body;
if (ObjectHelper.isNotEmpty(string)) {
rootNode.set("body", READER.readValue(string));
}
} else if (body instanceof InputStream) {
try (InputStream stream = (InputStream) body) {
if (stream.available() > 0) {
rootNode.set("body", READER.readValue(stream));
}
}
} else if (body != null) {
rootNode.putPOJO("body", body);
}
final String newBody = Json.toString(rootNode);
final Message replacement = new DefaultMessage(exchange.getContext());
replacement.copyFromWithNewBody(message, newBody);
ExchangeHelper.replaceMessage(exchange, replacement, false);
}
代码示例来源:origin: io.syndesis.server/server-api-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/server/dao/deployment.json"))
.read("$..[?(@['id'] == 'swagger-connector-template')]", new TypeRef<List<ConnectorTemplate>>() {
// type token pattern
});
return templates.get(0);
}
}
代码示例来源:origin: io.syndesis.server/server-connector-generator
private static ObjectNode createSchemaFromModelImpl(final String name, final Model model) {
final ObjectNode schema = Json.convertValue(model, ObjectNode.class);
final String title = determineTitleOf(name, model);
return JsonSchemaHelper.createJsonSchema(title, schema);
}
代码示例来源: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-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-connector-generator
final ObjectNode json = Json.convertValue(swagger, ObjectNode.class);
json.remove(Arrays.asList("info", "tags", "definitions", "externalDocs"));
return Json.writer().writeValueAsString(json);
} catch (final JsonProcessingException e) {
throw new IllegalStateException("Unable to serialize minified OpenAPI specification", e);
代码示例来源:origin: io.syndesis.server/server-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/server/dao/deployment.json"))
.read("$..[?(@['id'] == 'swagger-connector-template')]", new TypeRef<List<ConnectorTemplate>>() {
// type token pattern
});
return templates.get(0);
}
}
代码示例来源:origin: io.syndesis.server/server-api-generator
private static ObjectNode createSchemaFromModelImpl(final String name, final Model model) {
final ObjectNode schema = Json.convertValue(model, ObjectNode.class);
final String title = determineTitleOf(name, model);
return JsonSchemaHelper.createJsonSchema(title, schema);
}
代码示例来源: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.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
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-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.connector/connector-support-processor
private static JsonNode schema() {
final ObjectNode schema = Json.copyObjectMapperConfiguration().createObjectNode();
final ObjectNode parameters = schema.putObject("properties").putObject("parameters").putObject("properties");
parameters.putObject("h1");
parameters.putObject("h2");
parameters.putObject("h3");
return schema;
}
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!