本文整理汇总了Java中com.fasterxml.jackson.dataformat.yaml.YAMLGenerator类的典型用法代码示例。如果您正苦于以下问题:Java YAMLGenerator类的具体用法?Java YAMLGenerator怎么用?Java YAMLGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
YAMLGenerator类属于com.fasterxml.jackson.dataformat.yaml包,在下文中一共展示了YAMLGenerator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的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;
}
示例2: createObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的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;
}
示例3: providesYamlMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
@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;
}
示例4: createYamlMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public static ObjectMapper createYamlMapper() {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
.configure(YAMLGenerator.Feature.USE_NATIVE_OBJECT_ID, false)
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY).
enable(SerializationFeature.INDENT_OUTPUT).
disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS).
disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
return objectMapper;
}
示例5: createJacksonGenerator
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public YAMLGenerator createJacksonGenerator(StringWriter out) throws SchemaException{
try {
MidpointYAMLFactory factory = new MidpointYAMLFactory();
MidpointYAMLGenerator generator = (MidpointYAMLGenerator) factory.createGenerator(out);
generator.setPrettyPrinter(new DefaultPrettyPrinter());
generator.setCodec(configureMapperForSerialization());
return generator;
} catch (IOException ex){
throw new SchemaException("Schema error during serializing to JSON.", ex);
}
}
示例6: yamlFactory
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
private static YAMLFactory yamlFactory() {
return
new YAMLFactory().
disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER).
disable(YAMLGenerator.Feature.CANONICAL_OUTPUT).
enable(YAMLGenerator.Feature.SPLIT_LINES).
enable(YAMLGenerator.Feature.MINIMIZE_QUOTES).
enable(YAMLGenerator.Feature.USE_NATIVE_OBJECT_ID).
enable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
}
示例7: EmbulkOperatorFactory
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
@Inject
public EmbulkOperatorFactory(CommandExecutor exec, TemplateEngine templateEngine, CommandLogger clog, ObjectMapper mapper)
{
this.exec = exec;
this.clog = clog;
this.templateEngine = templateEngine;
this.mapper = mapper;
this.yaml = new YAMLFactory()
.configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false);
}
示例8: YamlMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
@Inject
public YamlMapper(ObjectMapper mapper)
{
this.yaml = new YAMLFactory()
.configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false);
this.mapper = mapper;
}
示例9: writeFile
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public <T> void writeFile(File file, T value)
throws IOException
{
file.getParentFile().mkdirs();
// TODO use yaml if file path ends with dig or yml, otherwise use json?
try (YAMLGenerator out = yaml.createGenerator(new FileOutputStream(file))) {
// TODO write to a String first, then write to file. to not create partially-written broken file
mapper.writeValue(out, value);
}
}
示例10: toYaml
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public <T> String toYaml(T value)
{
try {
StringWriter writer = new StringWriter();
try (YAMLGenerator out = yaml.createGenerator(writer)) {
mapper.writeValue(out, value);
}
return writer.toString();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例11: toYaml
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
/**
* Convert this RAML object to Yaml.
*
* @return Yaml string.
* @throws IOException If something goes wrong.
*/
public String toYaml() throws IOException {
YAMLMapper mapper = new YAMLMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, false);
mapper.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
return "#%RAML 1.0\n" + mapper.writer().withDefaultPrettyPrinter().writeValueAsString(this);
}
示例12: write
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public void write(YAMLGenerator generator, JsonNode merged) throws JsonProcessingException, IOException {
mapper.writeTree(generator, merged);
}
示例13: createObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
/**
* 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);
}
示例14: YAMLConfigurationProvider
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; //导入依赖的package包/类
public YAMLConfigurationProvider(String fileName) {
this.fileName = fileName;
factory = new YAMLFactory();
mapper = new ObjectMapper(factory);
factory.configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false);
}