You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a yaml file that I want to read into Map<String, String>:
events:
key1: val1
key2: val2
key3: val3
This piece of code is working fine.
public class EventGenerator {
private Map<String, String> events;
public Map<String, String> getEvents() {
return this.events;
}
public void setEvents() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
FileInputStream fis = new FileInputStream("file.yaml");
EventGenerator eventGenerator = mapper.readValue(fis, EventGenerator.class);
fis.close();
System.out.print(eventGenerator.getEvents());
} catch (IOException e) {
e.printStackTrace();
}
}
}
But when I pass path of yaml file as a String (and/or File) argument
public void setEvents(String filePath) {
// same code
FileInputStream fis = new FileInputStream(filePath)
// same code
}
I'm getting an exception
jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String
Also, when I override the setEvents() method and have both setEvents() and setEvents(String filePath) then neither are working and both are giving the above exception.
UPD (sorry, forgot to add pom)
jackson pom dependencies:
I have a yaml file that I want to read into Map<String, String>:
This piece of code is working fine.
But when I pass path of yaml file as a String (and/or File) argument
I'm getting an exception
Also, when I override the setEvents() method and have both setEvents() and setEvents(String filePath) then neither are working and both are giving the above exception.
UPD (sorry, forgot to add pom)
jackson pom dependencies:
The text was updated successfully, but these errors were encountered: