Amisha Perera Amisha Perera - 1 year ago 80
Java Question

How to get different types of JSON objects form a single call in JAX-RS Jersey 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. Is it OK do do it in a single call?

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download