I have a yaml file with data that looks like this:
dog:
animalId: dog00
animalName: Dog
animalFamily: Canidae
cat:
animalId: cat00
animalName: Cat
animalFamily: Felidae
elephant:
animalId: elpnt
animalName: Elephant
animalFamily: Elephantidae
...
(Update: I don't have control over the yaml file)
How can I deserialise this into a list of 'animal' objects in Java?
My Animal class looks like this
public class Animal {
private String animalId;
private String animalName;
private String animalFamily;
// getters, setters, constructors
}
I am trying to use jackson as follows
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
CollectionType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Animal.class);
List<Animal> animals = mapper.readValue(new File("src/main/resources/animals.yaml"), listType);
but I get the error
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of 'java.util.ArrayList<Animal>' out of START_OBJECT token