1

I am using AJAX to fetch a list of Company objects from database. I have added @ResponseBody to my controller method. And jackson-mapper-asl dependency. Below is AJAX call:

$.ajax({
        type : 'GET',
        url : $("#contextpath").val() + '/getCompanyList',
        success : function(response) {
            alert(response);
        }
    });

Controller method:

@RequestMapping(value="/getCompanyList", method=RequestMethod.GET)
public @ResponseBody List<Company> getCompanyList() {
    logger.debug("reached controller getCompanyList");
    return companyServices.getCompanyList();
}

But I am getting error

No converter found for return value of type: class java.util.ArrayList

Secondly, Is there a way to return list of Java objects to AJAX without converting it to JSON ?

1 Answer 1

2

But I am getting error

looks like you are missing an Ajax lib (Jackson for example) or the converter is not registered, maybe the mime type (mapping) is missing

Is there a way to return list of Java objects to AJAX without converting it to JSON ?

For conversation between an server and a client, it is required that that transferted date is serialized into some format and the client deserialize it. (Typical formats are Json, XML, and many different binary formats). For AJAX it is common to use JSON (not so often XML). To answer your question: you could use an other format (for example XML) but you must serialize it! But JSON has the best support for AJAX on client and server side

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.