0

I am trying to send some data as JSON to a Spring controller. Here's the code:

    $(document).ready(function() {
        $("#searchbutton").click(function() {
            $.ajax({
                type: "POST",
                url: "/cinestop/searchMovie",
                data: JSON.stringify(getQuery()),
                contentType: "application/json; charset=UTF-8",
                Accept: "application/json",
            });
        });
    });

    function getQuery() {
        var obj = {}
        obj["title"] = $("#home_searchMediaInputText").val();
        return obj;
    }

Here is my Spring controller:

@RequestMapping(method = RequestMethod.POST, value = "/searchMovie")
    public ModelAndView displayMatchingMovies(@RequestBody final MovieQueryModel movieQuery) {
        //correct the spelling first, and then search, to be done

        System.out.println(movieQuery.getTitle());
        List<MovieInfoModelList> matchingMovieModels = movieInfoDaoImpl.getMovieInfoForListing(movieQuery.getTitle());
        return null;
    }

I have Jackson set-up and all, but the server does not seem to understand the JSON sent by the client. Can someone tell me what I might be doing wrong?

Thanks!

0 Answers0