Reputation: 836
I've been creating class, which would be responsible for getting all my settings from an yml file. This class looks like this :
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);
}
}
But I get the exception in mapper.readValue(...) method
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
Here's my yml file :
test: "hello"
How can I fix this issue?
Upvotes: 1
Views: 759
Reputation: 10853
Looks like the getProperties()
method is being called several times.
The input stream field initialized in the constructor. It has a file pointer variable which is updated every time when you read from it. The exception occurs when the input stream reaches the end of file.
Try moving the YAML parsing to the constructor.
Upvotes: 1