1
我一直在創建類,它將負責從yml文件中獲取所有設置。這個類看起來是這樣的:從YAML文件讀取時發生JsonMappingException:由於輸入結束而無法映射內容
public class TestsConfiguration extends Configuration {
public TestsConfiguration() {
this.sourceYAML = this.getClass().getResourceAsStream("test.yml");
}
public TestsConfiguration(File sourceYAML) throws FileNotFoundException {
this.sourceYAML = new FileInputStream(sourceYAML);
}
public class PropertiesContainer {
@JsonProperty
private String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
private final InputStream sourceYAML;
public PropertiesContainer getProperties() throws IOException {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
return mapper.readValue(sourceYAML, PropertiesContainer.class);
}
}
但我得到mapper.readValue除外(...)方法
com.fasterxml.jackson.databind.JsonMappingException:沒有內容映射由於最終的輸入
這是我的YML文件:
test: "hello"
我該如何解決這個問題?