當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。