3

I'm trying to perform a simple GET and when I run and insert the directory it returns an empty array:

This is my class:

public class Movie {
  String directory;
  String name;
  boolean isPlaying;
  int watchedCounter;

  public Movie(String directory, String name, boolean isPlaying, int watchedCounter) {
    this.directory = directory;
    this.name = name;
    this.isPlaying = isPlaying;
    this.watchedCounter = watchedCounter;
  }
}

My Controller:

@RestController
@RequestMapping(path = "/api/vod")
public class MovieConroller {
  private final MovieService movieService;

  @Autowired
  public MovieConroller(MovieService movieService) {
    this.movieService = movieService;
  }

  @GetMapping
  public List < Movie > getMovies() {
    return movieService.getMovies();
  }
}

My Service:

@Service
public class MovieService {
  public List < Movie > getMovies() {
    List < Movie > movies = new ArrayList < > ();
    movies.add(new Movie("home", "film.avi", true, 0));
    movies.add(new Movie("house", "fil2m.avi", false, 1));
    return movies;
  }
}

And this is my application properties:

spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=ad
spring.data.mongodb.password=pas
spring.data.mongodb.database=mov
spring.data.mongodb.port=27017
spring.data.mongodb.host=localhost
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false

The URL : http://localhost:8080/api/vod
Result : [{}{}]

Can someone please assists?
Regards

2
  • 1
    Do you have getters and setters into Movie class? Commented Nov 14, 2021 at 19:46
  • Hi, no. This is the real project Commented Nov 14, 2021 at 19:56

1 Answer 1

6

The problem is the lack of getters and setters.

Usually it thrown an error, but using spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false it returns {} because can't serialize the objects.

If you add getters and setters it will return the list with objects filled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.