Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to return this in my java method

C#
return Json(new
                 {
                     Success = true,
                     Redirect = url,
                    //I want to return stock object here,
                 });



Java
@POST
@Path("/posting")
@Consumes({ MediaType.APPLICATION_JSON })
public User posting(User stock)  {

    //other code here
     boolean Success;
     String Redirect;

     //Below code is incorrect
     return Json(new
             {
                 Success = true,
                 Redirect = url,
                //I want to return stock object here,
             });
}


How can i return this method using JsonObject?
Posted

1 solution

@POST
@Path("/posting")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public javax.ws.rs.core.Response posting(User stock)  {

    //other code here
    boolean success;
    String redirect;

    ResponseDTO dto = new ResponseDTO();//Simple class to hold return values (value object)
    dto.setSuccess(success);
    dto.setRedirect(redirect);

    return javax.ws.rs.core.Response.ok(dto).build();

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900