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

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

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

Json.copyObjectMapperConfiguration介绍

[英]The name of this method is super awkward to remind you that there aren't many cases for you to use it. It's main usage is in tests, where you might have reason to configure differently advanced parameters. This method creates a copy of an ObjectMapper.
[中]这个方法的名称非常尴尬,它提醒您使用它的情况并不多。它的主要用途是在测试中,您可能有理由配置不同的高级参数。此方法创建ObjectMapper的副本。

代码示例

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

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

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

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 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.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;
  }
}

相关文章