当前位置: 首页>>代码示例>>Java>>正文


Java YAMLFactory类代码示例

本文整理汇总了Java中com.fasterxml.jackson.dataformat.yaml.YAMLFactory的典型用法代码示例。如果您正苦于以下问题:Java YAMLFactory类的具体用法?Java YAMLFactory怎么用?Java YAMLFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


YAMLFactory类属于com.fasterxml.jackson.dataformat.yaml包,在下文中一共展示了YAMLFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllPages

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
private static Map<String, MobileScreen> getAllPages(String filePath) throws Throwable {
    Map<String, MobileScreen> pages = new HashMap<>();
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {
        Iterator it = FileUtils.iterateFiles(new File(filePath), new String[]{"yaml"}, false);

        while (it.hasNext()) {
            File file = (File) it.next();
            MobileScreen mobileScreen = getPage(file);

            System.out.println("Name of the file : "+file.getName());
            System.out.println("****** :- " + mobileScreen.getPageName());
            System.out.println(ReflectionToStringBuilder.toString(mobileScreen, ToStringStyle.MULTI_LINE_STYLE));

            pages.put(mobileScreen.getPageName(), mobileScreen);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e.getCause();
    }
    return pages;
}
 
开发者ID:AshokKumarMelarkot,项目名称:msa-cucumber-appium,代码行数:24,代码来源:MobileApp.java

示例2: createObjectMapper

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
    final YAMLFactory yamlFactory = new YAMLFactory()
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
        .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
        .configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);

    ObjectMapper mapper = new ObjectMapper(yamlFactory)
        .registerModule(new Jdk8Module())
        .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
        .enable(SerializationFeature.INDENT_OUTPUT)
        .disable(SerializationFeature.WRITE_NULL_MAP_VALUES);

    for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
        mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
    }

    return mapper;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:20,代码来源:YamlHelpers.java

示例3: createObjectMapper

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
    final YAMLFactory yamlFactory = new YAMLFactory()
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
        .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
        .configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);

    ObjectMapper mapper = new ObjectMapper(yamlFactory)
        .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
        .enable(SerializationFeature.INDENT_OUTPUT)
        .disable(SerializationFeature.WRITE_NULL_MAP_VALUES);

    for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
        mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
    }

    return mapper;
}
 
开发者ID:syndesisio,项目名称:syndesis-integration-runtime,代码行数:19,代码来源:YamlHelpers.java

示例4: testParseXmEntitySpecFromYml

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
@Test
public void testParseXmEntitySpecFromYml() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    XmEntitySpec xmEntitySpec = mapper.readValue(new File(SPEC_PATH.toString()), XmEntitySpec.class);

    assertNotNull(xmEntitySpec);
    assertNotNull(xmEntitySpec.getTypes());
    assertEquals(5, xmEntitySpec.getTypes().size());
    assertEquals("TYPE1", xmEntitySpec.getTypes().get(0).getKey());
    assertEquals("TYPE2", xmEntitySpec.getTypes().get(1).getKey());
    assertEquals("TYPE1.SUBTYPE1", xmEntitySpec.getTypes().get(2).getKey());
    assertEquals("TYPE1-OTHER", xmEntitySpec.getTypes().get(3).getKey());
    assertEquals(1, xmEntitySpec.getTypes().get(0).getName().size());
    assertEquals(1, xmEntitySpec.getTypes().get(1).getName().size());
    assertEquals(2, xmEntitySpec.getTypes().get(2).getName().size());
    assertEquals(2, xmEntitySpec.getTypes().get(3).getName().size());
    assertNotNull(xmEntitySpec.getTypes().get(0).getDataSpec());
    assertNotNull(xmEntitySpec.getTypes().get(0).getDataForm());
    assertNotNull(xmEntitySpec.getTypes().get(0).getFastSearch());
    assertEquals(1, xmEntitySpec.getTypes().get(0).getFastSearch().size());
    assertEquals("typeKey:TYPE1*", xmEntitySpec.getTypes().get(0).getFastSearch().get(0).getQuery());
    assertFalse(xmEntitySpec.getTypes().get(0).getFastSearch().get(0).getName().isEmpty());
    assertEquals("NEW", xmEntitySpec.getTypes().get(0).getLinks().get(0).getBuilderType());
    assertNotNull("NEW", xmEntitySpec.getTypes().get(0).getLinks().get(0).getIcon());
    assertEquals("5STARS", xmEntitySpec.getTypes().get(2).getRatings().get(0).getStyle());
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:27,代码来源:XmEntitySpecUnitTest.java

示例5: readYAMLFile

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
@Test
public void readYAMLFile() {

    // new error-free endpoint
    Endpoint endpoint = resources.createEndpoint("GET", "/test-yaml-file", "200");

    // write yaml file on temporary directory
    ObjectMapper mapperJson = new ObjectMapper(new YAMLFactory());
    File file = TempIO.buildFile("read-yaml-file", ".lyre", resources.getDirectory(0));

    try {
        mapperJson.writeValue(file, endpoint);
    } catch (IOException e) {
        fail("Couldn't write on temporary file: " + e.getMessage());
    }

    reader.read(file);

    //should have a object node with yaml file on it.
    assertThat(reader.getObjectNodes()).isNotEmpty();
    assertThat(reader.getObjectNodes().get(file.getAbsolutePath())).isNotNull();

}
 
开发者ID:groovylabs,项目名称:lyre,代码行数:24,代码来源:ReaderTest.java

示例6: initRootLayout

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public void initRootLayout(Stage ps) throws IOException, URISyntaxException,
                                     QueryException {
    primaryStage = ps;
    anchor = new AnchorPane();
    VBox vbox = new VBox(locationBar(), anchor);
    primaryStage.setScene(new Scene(vbox, 800, 600));
    Map<String, String> parameters = getParameters().getNamed();
    String app = parameters.get("app");
    URL url = Utils.resolveResourceURL(getClass(), app);
    if (url == null) {
        throw new IllegalArgumentException(String.format("App resource not found: %s",
                                                         app));
    }
    application = new ObjectMapper(new YAMLFactory()).readValue(url.openStream(),
                                                                GraphqlApplication.class);
    endpoint = ClientBuilder.newClient()
                            .target(application.getEndpoint()
                                               .toURI());
    push(new PageContext(application.getRoot()));
    primaryStage.show();
}
 
开发者ID:ChiralBehaviors,项目名称:Kramer,代码行数:22,代码来源:SinglePageApp.java

示例7: objectMapper

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
private static ObjectMapper objectMapper(Format format) {
    ObjectMapper mapper = null;
    if (format == Format.YAML) {
        mapper = new ObjectMapper(new YAMLFactory());
    }
    else {
        mapper = new ObjectMapper();
    }
    new Jackson2ObjectMapperBuilder()
            .modulesToInstall(new MetadataModule(), new DefaultScalaModule())
            .serializationInclusion(JsonInclude.Include.NON_NULL)
            .serializationInclusion(JsonInclude.Include.NON_ABSENT)
            .serializationInclusion(JsonInclude.Include.NON_EMPTY)
            .featuresToEnable(SerializationFeature.INDENT_OUTPUT)
            .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
                    DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE,
                    DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .configure(mapper);
    return mapper;
}
 
开发者ID:atomist-attic,项目名称:rug-resolver,代码行数:21,代码来源:MetadataWriter.java

示例8: loadConfiguration

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
private static Configuration loadConfiguration(Path basePath) throws IOException {
    Path configFile = basePath.resolve(CONFIG_FILE);
    if (!Files.isReadable(configFile)) {
        throw new SchemaTransformerException(String.format(
                "Cannot read configuration file %s",
                configFile.toAbsolutePath().toString()));
    }
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    Configuration configuration = null;
    try {
        configuration = objectMapper.readValue(configFile.toFile(), Configuration.class);
    } catch (IOException e) {
        throw new RuntimeException("Error reading YAML configuration in " +
                configFile.toAbsolutePath().toString(), e);
    }
    validateConfiguration(basePath, configuration);
    return configuration;
}
 
开发者ID:gchq,项目名称:event-logging-schema,代码行数:19,代码来源:SchemaGenerator.java

示例9: loadConfigFromEnv

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public static <T> T loadConfigFromEnv(Class<T> configurationClass, final String path)
    throws IOException {
    LOGGER.info("Parsing configuration file from {} ", path);
    logProcessEnv();
    final Path configPath = Paths.get(path);
    final File file = configPath.toAbsolutePath().toFile();
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    final StrSubstitutor sub = new StrSubstitutor(new StrLookup<Object>() {
        @Override
        public String lookup(String key) {
            return System.getenv(key);
        }
    });
    sub.setEnableSubstitutionInVariables(true);

    final String conf = sub.replace(FileUtils.readFileToString(file));
    return mapper.readValue(conf, configurationClass);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:20,代码来源:YAMLConfigurationLoader.java

示例10: getEnvironmentConfig

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public EnvironmentConfig getEnvironmentConfig() {
    if (environmentConfig != null) {
        return environmentConfig;
    }

    if (file == null) {
        return null;
    }

    File environmentConfigFile = new File(file);
    if (! environmentConfigFile.exists() || environmentConfigFile.isDirectory()) {
        throw new IllegalArgumentException(String.format("The file: %s does not exist or is a directory", file));
    }

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    try {
        environmentConfig = mapper.readValue(environmentConfigFile, EnvironmentConfig.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to deserialize environment yaml", e);
    }

    return environmentConfig;
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:25,代码来源:CerberusCommand.java

示例11: testUpdate

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
protected void testUpdate(UrlPattern instancePattern) throws ResourceException, IOException {
    // Prepare body
    JsonNode body;
    ContentType contentType = resource.getResourceConfig().getContentType();
    String content = resource.getResourceConfig().getContent();
    if (contentType == ContentType.YAML) {
        body = new ObjectMapper(new YAMLFactory()).readTree(content);
    } else if (contentType == ContentType.JSON) {
        body = new ObjectMapper(new JsonFactory()).readTree(content);
    } else {
        throw new IllegalArgumentException("Can't process this type of content");
    }
    String jsonContent = new ObjectMapper(new JsonFactory()).writeValueAsString(body);

    // Update deployment
    instanceRule.stubFor(patch(instancePattern)
            .withRequestBody(equalTo(jsonContent))
            .withHeader("Content-Type", equalTo("application/merge-patch+json; charset=utf-8"))
            .willReturn(aResponse().withStatus(200)));

    resource.update();

    // Verify calls
    instanceRule.verify(1, patchRequestedFor(instancePattern));
}
 
开发者ID:qaware,项目名称:gradle-cloud-deployer,代码行数:26,代码来源:BaseKubernetesResourceTest.java

示例12: save

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
public void save(SharedSettings settings) {
	if (settings != null) {
		YAMLFactory yf = new YAMLFactory(new ObjectMapper());
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(configLocation);
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		try {
			yf.createGenerator(fos).writeObject(settings);
			getLogger().info("Settings saved.");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
 
开发者ID:Gliby,项目名称:VoiceChat-Base,代码行数:19,代码来源:VoiceChatShared.java

示例13: parse

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
@Override
public Bundle parse(InputStream in) throws JsonParseException, FileNotFoundException, IOException {

    char separator = '.';

    YAMLFactory yf = new YAMLFactory();
    ObjectMapper mapper = new ObjectMapper(yf);
    Map<String, Object> YAML_map = new LinkedHashMap<String, Object>();
    Bundle bundle = new Bundle();
    // Reads contents of YAML file and converts it to a hashmap
    YAML_map = mapper.readValue(in, new TypeReference<LinkedHashMap<String, Object>>() {
    });

    Map<String, String> resultMap = flattenMap("", YAML_map, new LinkedHashMap<String, String>(), separator);
    int sequenceNum = 0;
    for (Entry<String, String> entry : resultMap.entrySet()) {
        bundle.addResourceString(entry.getKey(), entry.getValue(), ++sequenceNum);
    }
    return bundle;
}
 
开发者ID:IBM-Cloud,项目名称:gp-java-tools,代码行数:21,代码来源:YMLResource.java

示例14: yamlMapper

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
@Bean
public YamlMapper yamlMapper(JacksonProperties jacksonProperties) {
    final YAMLFactory yamlFactory = new YAMLFactory();
    final ObjectMapper objectMapper = new ObjectMapper(yamlFactory);

    // leverage the deserialization settings used for JSON lenient processing
    for (Map.Entry<DeserializationFeature, Boolean> entry : jacksonProperties.getDeserialization().entrySet()) {
        if (entry.getValue()) {
            objectMapper.enable(entry.getKey());
        }
        else {
            objectMapper.disable(entry.getKey());
        }
    }

    return new YamlMapper(objectMapper);
}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:18,代码来源:GeneralConfig.java

示例15: createYamlFile

import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; //导入依赖的package包/类
/**
 * Creates the YAML file in the output location based on the Swagger metadata.
 *
 * @param swagger the Swagger metadata.
 *
 * @throws MojoExecutionException if any error was encountered while writing the YAML information to the file.
 */
private void createYamlFile(Swagger swagger) throws MojoExecutionException
{
    String yamlOutputLocation = outputDirectory + "/" + outputFilename;
    try
    {
        getLog().debug("Creating output YAML file \"" + yamlOutputLocation + "\"");

        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
        objectMapper.setPropertyNamingStrategy(new SwaggerNamingStrategy());
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        objectMapper.writeValue(new File(yamlOutputLocation), swagger);
    }
    catch (IOException e)
    {
        throw new MojoExecutionException("Error creating output YAML file \"" + yamlOutputLocation + "\". Reason: " + e.getMessage(), e);
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:26,代码来源:SwaggerGenMojo.java


注:本文中的com.fasterxml.jackson.dataformat.yaml.YAMLFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。