I am having trouble reading my JSON file back to it's respective class. I am using Jackson 2.6.3 API
ObjectMapper objectMapper = new ObjectMapper();
list<Movie>myMovies = objectMapper.readValue(JSONFile,objectMapper.getTypeFactory().constructCollectionType(List.class, Movie.class));
My Movie
class
public class Movie {
private List<String> reviews;
/*Some more variables here */
public Movie() { // default constructor
}
public List<String> getReviews(){
return this.reviews;
}
public void setReviews(String review){
this.reviews.add(review);
}
}
Error log
com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: java.util.ArrayList[0]->entity.Movie["reviews"])
at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:564)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:548)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:258)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2658)
at entity.Movie.loadMovies(Movie.java:427)
at myPackage.Application.main(Application.java:31)
Caused by: java.lang.NullPointerException
at entity.Movie.setReviews(Movie.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:97)
... 9 more
Sample of my JSON File
[
{
"movieID":1,
"title":"13",
"type":"DIGITAL",
"status":"COMING SOON",
"synopsis":null,
"director":null,
"mRating":"G",
"casts":null,
"showTimes":null,
"reviews":null,
}
]