This is list of movies.
public static List<Movie> movies;
static {
movies = new ArrayList<>();
movies.add(new Movie(1, "Fprd vs Ferrari", "Movie on Racing", "abcd", "xyz"));
movies.add(new Movie(2, "F2", "Comedy Movie", "Venkatesh", "Tamanna"));
movies.add(new Movie(3, "Titanic", "Movie", "Hero", "Heroine"));
}
this is update method:
public Result update(Http.Request request, int id) {
Movie movie = findById(id);
if (movie == null) {
return notFound("Movie not Found");
}
JsonNode jsonNode = request.body().asJson();
Movie movie1 = Json.fromJson(jsonNode, Movie.class);
movie1.setId(id);
int index = movies.indexOf(movie);
movies.set(index, movie1);
return ok(Json.toJson(movie1));
}
When I send the data using postman,example I will give only movieName then movie will update, but remaining fields will get null value.
But I want to update data, If I did not send the any field it will store with existing value from object.
How can I do this..what is the condition for that
Actually, your request in contains the only movieName. And you're not updating that name with movie object. You have to update all values of movie1 to movie object then it will get an update like this.