com.fasterxml.jackson.dataformat.yaml.YAMLFactory类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(742)

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

YAMLFactory介绍

暂无

代码示例

代码示例来源:origin: google/data-transfer-project

@VisibleForTesting
void parseRetryLibrary(InputStream in) {
 if (in != null) {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  try {
   settings.put("retryLibrary", mapper.readValue(in, RetryStrategyLibrary.class));
  } catch (IOException e) {
   throw new RuntimeException("Could not parse extension settings", e);
  }
 }
}

代码示例来源:origin: bootique/bootique

@Override
  public Optional<JsonNode> apply(InputStream t) {
    try {
      YAMLParser parser = yamlFactory.createParser(t);
      return Optional.ofNullable(mapper.readTree(parser));
    } catch (IOException e) {
      throw new RuntimeException("Error reading config data", e);
    }
  }
}

代码示例来源:origin: redisson/redisson

@Override
public YAMLFactory copy()
{
  _checkInvalidCopy(YAMLFactory.class);
  return new YAMLFactory(this, null);
}

代码示例来源:origin: swagger-api/swagger-core

protected static ObjectMapper createYaml() {
  YAMLFactory factory = new YAMLFactory();
  factory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
  factory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES);
  factory.enable(YAMLGenerator.Feature.SPLIT_LINES);
  factory.enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS);
  return create(factory);
}

代码示例来源:origin: org.ballerinalang/language-server-core

private static String convertToJson(String yamlString) throws IOException {
  ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
  Object obj = yamlReader.readValue(yamlString, Object.class);
  ObjectMapper jsonWriter = new ObjectMapper();
  return jsonWriter.writeValueAsString(obj);
}

代码示例来源:origin: lenskit/lenskit

/**
 * Load one or more data sets from a YAML manifest file.
 * @param file The path to the YAML manifest file.
 * @return The list of data sets.
 */
public static List<DataSet> load(Path file) throws IOException {
  YAMLFactory factory = new YAMLFactory();
  ObjectMapper mapper = new ObjectMapper(factory);
  JsonNode node = mapper.readTree(file.toFile());
  return fromJSON(node, file.toAbsolutePath().toUri());
}

代码示例来源:origin: apache/pulsar

public static ObjectMapper createYaml() {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  // forward compatibility for the properties may go away in the future
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
  mapper.setSerializationInclusion(Include.NON_NULL);
  return mapper;
}

代码示例来源:origin: org.openecomp.appc/appc-config-params-provider

public String convertPDToYaml(PropertyDefinition propertyDefinition) throws JsonParseException, JsonMappingException, IOException{
  String yamlContent = null;
  if(propertyDefinition != null){
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    yamlContent = mapper.writeValueAsString(propertyDefinition);	        
  }
  return yamlContent;
}

代码示例来源:origin: Graylog2/graylog2-server

private NetFlowV9FieldTypeRegistry(InputStream definitions) throws IOException {
  this(definitions, new ObjectMapper(new YAMLFactory()));
}

代码示例来源:origin: rakam-io/rakam

ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.registerModule(new SimpleModule() {
  @Override
  public void setupModule(SetupContext context) {
Recipe recipe;
try {
  recipe = mapper.readValue(stream, Recipe.class);
} catch (IOException e) {
  binder.addError("'recipes' file %s couldn't parsed: %s", recipeConfig, e.getMessage());

代码示例来源:origin: rapidoid/rapidoid

private static ObjectMapper mapper() {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.registerModule(new AfterburnerModule());
  return mapper;
}

代码示例来源:origin: zalando/intellij-swagger

private String convertToJsonIfNecessary(final PsiFile file) throws Exception {
  if (fileDetector.isMainSwaggerJsonFile(file) || fileDetector.isMainOpenApiJsonFile(file)) {
   return file.getText();
  }

  final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  final JsonNode jsonNode = mapper.readTree(file.getText());
  return new ObjectMapper().writeValueAsString(jsonNode);
 }
}

代码示例来源:origin: stackoverflow.com

public MyYamlFile readYaml(final File file) {
  final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
  return mapper.readValue(file, MyYamlFile.class);
}

代码示例来源:origin: com.github.redhatqe.polarizer/reporter

public static <T> void toYaml(T cfg, String path) throws IOException {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
  writer.writeValue(new File(path), cfg);
}

代码示例来源:origin: flaxsearch/BioSolr

@Override
public IndexerConfiguration loadConfiguration() throws IOException {
  FileReader reader = new FileReader(configFile);
  final JsonNode node = mapper.readTree(yamlFactory.createParser(reader));
  final IndexerConfiguration config = mapper.readValue(new TreeTraversingParser(node), IndexerConfiguration.class);
  
  // Close the file reader
  reader.close();
  
  return config;
}

代码示例来源:origin: funktionio/funktion-connectors

/**
 * Creates a configured Jackson object mapper for parsing YAML
 */
public static ObjectMapper createObjectMapper() {
  YAMLFactory yamlFactory = new YAMLFactory();
  yamlFactory.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);
  return new ObjectMapper(yamlFactory);
}

代码示例来源:origin: io.fabric8.jenkins.plugins/openshift-sync

public static String dumpWithoutRuntimeStateAsYaml(HasMetadata obj) throws JsonProcessingException {
 ObjectMapper statelessMapper = new ObjectMapper(new YAMLFactory());
 statelessMapper.addMixInAnnotations(ObjectMeta.class, ObjectMetaMixIn.class);
 statelessMapper.addMixInAnnotations(ReplicationController.class, StatelessReplicationControllerMixIn.class);
 return statelessMapper.writeValueAsString(obj);
}

代码示例来源:origin: HubSpot/Singularity

@Provides
@Singleton
@Named(YAML)
public ObjectMapper providesYamlMapper() {
 final YAMLFactory yamlFactory = new YAMLFactory();
 yamlFactory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
 final ObjectMapper mapper = new ObjectMapper(yamlFactory);
 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 mapper.registerModule(new GuavaModule());
 mapper.registerModule(new ProtobufModule());
 return mapper;
}

代码示例来源:origin: org.onap.appc/appc-config-params-provider

private void logArtifact(PropertyDefinition artifact) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    String stringArtifact = null;
    try {
      stringArtifact = mapper.writeValueAsString(artifact);
      Log.info("Received PropertyDefinition:\n" + stringArtifact);
    } catch (JsonProcessingException e) {
      Log.error("Exception while logging artifact:", e);
    }

  }
}

代码示例来源:origin: HubSpot/Singularity

@Test
public void testMergedConfigs() throws Exception {
  final InputStream mergedConfigStream = buildConfigurationSourceProvider(DEFAULT_PATH).open(OVERRIDE_PATH);
  final SingularityConfiguration mergedConfig = objectMapper.readValue(YAML_FACTORY.createParser(mergedConfigStream), SingularityConfiguration.class);
  assertEquals(10000, mergedConfig.getCacheTasksMaxSize());
  assertEquals(500, mergedConfig.getCacheTasksInitialSize());
  assertEquals(100, mergedConfig.getCheckDeploysEverySeconds());
  assertEquals("baseuser", mergedConfig.getDatabaseConfiguration().get().getUser());
  assertEquals("overridepassword", mergedConfig.getDatabaseConfiguration().get().getPassword());
}

相关文章