Amisha Perera Amisha Perera - 3 months ago 7
reST (reStructuredText) Question

How to get different types of JSON object form single call in JAX-RS Jeesey Restful web services

I want to get three different types of objects (Object list) from a single service call. It's OK to get different objects from different call.

Answer

If the number of different objects you want to return is limited to 3, then you can create a result object, which has properties for each of the three different objects you want to return

public class Result {

    private ResultOne resultOne;
    private ResultTwo resultTwo;
    private ResultThree resultThree;

    public ResultOne getResultOne() {
        return resultOne;
    }

    public void setResultOne(ResultOne resultOne) {
        this.resultOne = resultOne;
    }

    public ResultTwo getResultTwo() {
        return resultTwo;
    }

    public void setResultTwo(ResultTwo resultTwo) {
        this.resultTwo = resultTwo;
    }

    public ResultThree getResultThree() {
        return resultThree;
    }

    public void setResultThree(ResultThree resultThree) {
        this.resultThree = resultThree;
    }
}

If you want to return a true list of objects, see Does rest supports arraylist of objects?