本文整理汇总了Java中com.fasterxml.jackson.dataformat.yaml.YAMLParser类的典型用法代码示例。如果您正苦于以下问题:Java YAMLParser类的具体用法?Java YAMLParser怎么用?Java YAMLParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
YAMLParser类属于com.fasterxml.jackson.dataformat.yaml包,在下文中一共展示了YAMLParser类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParse_FromJson
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
@Test
public void testParse_FromJson() throws IOException {
YAMLParser parser = new YAMLFactory().createParser("3.5 4.5");
DoubleRange r = new ObjectMapper().readValue(parser, DoubleRange.class);
assertNotNull(r);
assertEquals(3.5, r.getWarningThreshold().doubleValue(), 0.00001);
assertEquals(4.5, r.getCriticalThreshold().doubleValue(), 0.00001);
}
示例2: testParse_FromJson
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
@Test
public void testParse_FromJson() throws IOException {
YAMLParser parser = new YAMLFactory().createParser("3 4");
IntRange r = new ObjectMapper().readValue(parser, IntRange.class);
assertNotNull(r);
assertEquals(Integer.valueOf(3), r.getWarningThreshold());
assertEquals(Integer.valueOf(4), r.getCriticalThreshold());
}
示例3: factory
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
private ConfigurationFactory factory(String yaml) {
// not using a mock; making sure all Jackson extensions are loaded
JacksonService jacksonService = new DefaultJacksonService(typesFactory.getTypes());
YAMLParser parser;
try {
parser = new YAMLFactory().createParser(yaml);
JsonNode rootNode = jacksonService.newObjectMapper().readTree(parser);
return new JsonNodeConfigurationFactory(rootNode, jacksonService.newObjectMapper());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例4: apply
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
@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);
}
}
示例5: readYaml
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
private static JsonNode readYaml(String yaml) {
ByteArrayInputStream in = new ByteArrayInputStream(yaml.getBytes());
try {
YAMLParser parser = new YAMLFactory().createParser(in);
return new ObjectMapper().readTree(parser);
} catch (IOException e) {
throw new RuntimeException("Error reading config file", e);
}
}
示例6: readValue
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
protected <T> T readValue(Class<T> type, ObjectMapper mapper, String yml) throws IOException {
YAMLParser parser = new YAMLFactory().createParser(yml);
JsonNode node = mapper.readTree(parser);
assertNotNull(node);
return mapper.readValue(new TreeTraversingParser(node), type);
}
示例7: readFile
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
public <T> T readFile(File file, Class<T> type)
throws IOException
{
// TODO use yaml if file path ends with dig or yml, otherwise use json?
try (YAMLParser out = yaml.createParser(new FileInputStream(file))) {
// TODO write to a String first, then write to file. to not create partially-written broken file
return mapper.readValue(out, type);
}
}
示例8: loadConfiguration
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
public static Configuration loadConfiguration(InputStream inputStream) throws IOException {
YAMLFactory yamlFactory = new YAMLFactory(new ObjectMapper());
YAMLParser yamlParser = yamlFactory.createParser(inputStream);
return yamlParser.readValueAs(Configuration.class);
}
示例9: loadBody
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
public void loadBody(final String filename, final EntityEdit edit) throws IOException
{
// final InputStream fileStream = loader.getResourceAsStream(filename);
final InputStream fileStream = new FileInputStream(filename);
final YAMLFactory factory = new YAMLFactory();
final YAMLParser parser = factory.createParser(fileStream);
int str = 0, agi = 0, con = 0, skin = 0, sight = 0;
boolean herbivore = false, carnivore = false;
parser.nextToken(); // START_OBJECT
while (parser.nextToken() != null)
{
final String name = parser.getCurrentName();
if (name == null)
break;
parser.nextToken(); // get value for this "name"
switch (name)
{
case "strength":
str = parser.getIntValue();
edit.create(Strength.class).value = Util.clamp(str, -2, 2);
break;
case "agility":
agi = parser.getIntValue();
edit.create(Agility.class).value = Util.clamp(agi, -2, 2);
break;
case "constitution":
con = parser.getIntValue();
edit.create(Constitution.class).value = Util.clamp(con, -2, 2);
break;
case "skin":
skin = parser.getIntValue();
edit.create(Skin.class).value = Util.clamp(skin, -2, 2);
break;
case "sight":
sight = parser.getIntValue();
edit.create(Sight.class).value = Util.clamp(sight, 1, 18);
break;
case "herbivore":
herbivore = parser.getBooleanValue();
if (herbivore)
edit.create(Herbivore.class);
break;
case "carnivore":
carnivore = parser.getBooleanValue();
if (carnivore)
edit.create(Carnivore.class);
break;
case "underwater":
edit.create(Underwater.class);
break;
}
}
// Secondary Attributes
final int size = Math.round((con - agi) / 2f);
edit.create(Size.class).set(size);
edit.create(Stamina.class).set((5 + str + con) * 100); // FIXME for debug, reduce/tweak later
edit.create(Speed.class).set((con - str - agi + 6) / 12f);
edit.create(Health.class).set((con + 3) * 10);
// Tertiary Attributes
// a fish does not need to eat, for now
if (herbivore || carnivore)
edit.create(Hunger.class).set(0f, (size / 2f) + 2f);
}
示例10: fromPath
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; //导入依赖的package包/类
/**
* Constructs a {@code JsonToggleMap} from a {@link Path}
* representing a toggle specification file.
*
* Toggle specification file can be in either JSON or YAML format.
*
* @param <T> The toggle input type. The toggle is applied to
* instances of type {@code T}.
* @param path A {@code Path} to a toggle specification file on the
* local file system.
* @return A {@code JsonToggleMap} backed by a toggle specification
* drawn from the given local file.
*/
public static <T> JsonToggleMap<T> fromPath(Path path) {
return new JsonToggleMap<T>(() -> {
try {
final YAMLParser yamlParser = DEFAULT_YAML_FACTORY.createParser(path.toFile());
return DEFAULT_OBJECT_READER.<JsonNode>readTree(yamlParser).elements();
} catch (IOException err) {
return DEFAULT_OBJECT_READER.createArrayNode().elements();
}
});
}