本文整理汇总了Java中com.fasterxml.jackson.dataformat.yaml.YAMLMapper.readValue方法的典型用法代码示例。如果您正苦于以下问题:Java YAMLMapper.readValue方法的具体用法?Java YAMLMapper.readValue怎么用?Java YAMLMapper.readValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.dataformat.yaml.YAMLMapper
的用法示例。
在下文中一共展示了YAMLMapper.readValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: robotInit
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
/**
* The method that runs when the robot is turned on. Initializes all subsystems from the map.
*/
public void robotInit() {
//Set up start time
Clock.setStartTime();
Clock.updateTime();
enabled = false;
//Yes this should be a print statement, it's useful to know that robotInit started.
System.out.println("Started robotInit.");
Yaml yaml = new Yaml();
try {
Map<?, ?> normalized = (Map<?, ?>) yaml.load(new FileReader(RESOURCES_PATH+"ballbasaur_map.yml"));
YAMLMapper mapper = new YAMLMapper();
String fixed = mapper.writeValueAsString(normalized);
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
robotMap = mapper.readValue(fixed, RobotMap.class);
} catch (IOException e) {
System.out.println("Config file is bad/nonexistent!");
e.printStackTrace();
}
//Read sensors
this.robotMap.getUpdater().run();
this.loggerNotifier = new Notifier(robotMap.getLogger());
this.driveSubsystem = robotMap.getDrive();
//Run the logger to write all the events that happened during initialization to a file.
robotMap.getLogger().run();
Clock.updateTime();
}
示例2: fromYamlFile
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
/**
* Parses metadata about the match from the given file.
* @param path the filename.
* @return the metadata about the match.
* @throws IOException when metadata cannot be read.
*/
public static Match fromYamlFile(Path path) throws IOException {
final YAMLMapper mapper = new MatchMetadataYamlMapper();
Match metadata;
try (Reader rd = Files.newBufferedReader(path, Charset.defaultCharset())) {
metadata = mapper.readValue(rd, Match.class);
}
return metadata;
}
示例3: robotInit
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
/**
* The method that runs when the robot is turned on. Initializes all subsystems from the map.
*/
public void robotInit() {
//Set up start time
Clock.setStartTime();
Clock.updateTime();
enabled = false;
//Yes this should be a print statement, it's useful to know that robotInit started.
System.out.println("Started robotInit.");
Yaml yaml = new Yaml();
try {
//Read the yaml file with SnakeYaml so we can use anchors and merge syntax.
Map<?, ?> normalized = (Map<?, ?>) yaml.load(new FileReader(RESOURCES_PATH + mapName));
YAMLMapper mapper = new YAMLMapper();
//Turn the Map read by SnakeYaml into a String so Jackson can read it.
String fixed = mapper.writeValueAsString(normalized);
//Use a parameter name module so we don't have to specify name for every field.
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
//Add mix-ins
mapper.registerModule(new WPIModule());
//Deserialize the map into an object.
robotMap = mapper.readValue(fixed, RobotMap.class);
} catch (IOException e) {
//This is either the map file not being in the file system OR it being improperly formatted.
System.out.println("Config file is bad/nonexistent!");
e.printStackTrace();
}
//Read sensors
this.robotMap.getUpdater().run();
//Set fields from the map.
this.loggerNotifier = new Notifier(robotMap.getLogger());
//Run the logger to write all the events that happened during initialization to a file.
robotMap.getLogger().run();
Clock.updateTime();
}
示例4: setup
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
@Before
public void setup() throws Exception
{
YAMLMapper mapper = new YAMLMapper();
ClassPathResource resource = new ClassPathResource("fixtures/declaration.yml");
fixture = mapper.readValue(resource.getFile(), Declaration.class);
CloudFoundryFacade cf = mock(CloudFoundryFacade.class);
UaaFacade uaa = mock(UaaFacade.class);
handlerFactory = new HandlerConfig().handlerFactory(cf, uaa);
builder = new HardcodedOrderedHandlerBuilder(handlerFactory);
}
示例5: unmarshallsCorrectly
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
@Test
public void unmarshallsCorrectly() throws Exception
{
ClassPathResource resource = new ClassPathResource("fixtures/declaration.yml");
YAMLMapper mapper = new YAMLMapper();
Declaration declaration = mapper.readValue(resource.getFile(), Declaration.class);
assertThat(declaration.schemaVersion, is(2));
assertThat(declaration.org.name, is("my-lovely-org"));
}
示例6: works
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; //导入方法依赖的package包/类
@Test
public void works() throws IOException {
Money money = new Money();
money.setValue( "12374.34" );
money.setCurrency( "EUR" );
YAMLMapper mapper = new YAMLMapper();
String yaml = mapper.writeValueAsString( money );
logger.info( "\n" + yaml );
Money copy = mapper.readValue( yaml, Money.class );
Assert.assertTrue( EqualsBuilder.reflectionEquals( copy, money ) );
}