title: How to create generic json response Object in java?
body: <p>I am new to java and creating some Restful services in netbeans using jersey framework.</p>
  
  <p>I have created many GET, POST web services which is having different different type of responses which are basically Model Objects and depending upon media type I am getting JSON or XML. </p>
  
  <p>Some response is having only a single object which is being shown in JSON inside {}, and some are list which are in []. 
  I want to see a generic response format for all api responses. </p>
  
  <p><strong>Example-</strong>
  {"status":"0 or 1", "message":"any string message","result":"it can be a single object or a list of objects which is dynamic depending upon each web service response"}.</p>
  
  <p>Since here in java we need to created model objects for getting responses so I have created a ResponseModel which is having a status property , message property but don't know the type of result property because sometime it can have a single object or sometime a list so what type should I set for this property so that I can assign any thing to this and response will always be in same format for JSON or XML.</p>
  
  <p>I have created a static method with constructor which takes all these three parameters and create a ResponseModel object.</p>
  
  <p>Thanks in advance  </p>
  
  <p>EDITED- Code after Using "Object" as generic type</p>
  
  <pre><code>public static Response getResponseObjectIsValid(boolean isValid, String message,Object result)
  {
  
  
      if (isValid == true) { 
         LGSResponse response = new LGSResponse();
         response.setStatus(1);
         response.setMessage(message.length()&gt;0 ? message : "Success");
         response.setResult(result);
  
        return  Response.status(Status.OK).entity(response).build();
  
      }
      else 
      {
        LGSResponse response = new LGSResponse();
        response.setStatus(1);
         response.setMessage(message.length()&gt;0 ? message : "Failed");
         response.setResult(result);
  
         return  Response.status(Status.OK).entity(response).build();
      }
  }
  </code></pre>
  
  <p>Result Parameter is a normal model object.</p>