<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How to return JSON and HTTP status code together in remote service method</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=118875993" />
  <subtitle>How to return JSON and HTTP status code together in remote service method</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=118875993</id>
  <updated>2026-04-06T16:40:22Z</updated>
  <dc:date>2026-04-06T16:40:22Z</dc:date>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118909467" />
    <author>
      <name>Andrew Jardine</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118909467</id>
    <updated>2020-04-11T18:07:40Z</updated>
    <published>2020-04-11T18:07:40Z</published>
    <summary type="html">Ok I get it. The problem is that the methods want to return your entity. So all I can think of is, in your serviceImpl add a method that returns a JSONObject. In that custom method you define you can then, internally, call your service that returns your entity. Once you have the entity you can wrap it in a JSONObject that has an attribute with the status and an attribute with your entity. &lt;br /&gt;&lt;br /&gt;At the end of the day though, as Christoph has said, the response code is in the response headers anyway sooooo personally I think you should just use that.</summary>
    <dc:creator>Andrew Jardine</dc:creator>
    <dc:date>2020-04-11T18:07:40Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118909123" />
    <author>
      <name>ali yeganeh</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118909123</id>
    <updated>2020-04-11T17:59:42Z</updated>
    <published>2020-04-11T17:59:42Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Andrew Jardine:&lt;/div&gt;&lt;blockquote&gt;&lt;br /&gt;Are you trying to use one of the out of the box JSONWS services that Liferay provides? or are you working with one that you have generated?&lt;/blockquote&gt;Hi&lt;br /&gt;I produced it myself through the service builder .&lt;br /&gt;Now, I want  in my class ( *ServiceImpl ),&lt;strong&gt; return JSON and HTTP status code together?&lt;/strong&gt;</summary>
    <dc:creator>ali yeganeh</dc:creator>
    <dc:date>2020-04-11T17:59:42Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118907704" />
    <author>
      <name>Andrew Jardine</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118907704</id>
    <updated>2020-04-11T15:49:21Z</updated>
    <published>2020-04-11T15:49:21Z</published>
    <summary type="html">I&amp;#39;m with you on this one Christoph, the Whiteboard stuff is awesome and I have recently being playing around a lot with the Headless capabilities as well. &lt;br /&gt;&lt;br /&gt;For the JSON services, I&amp;#39;ve never actually tried it myself, but I am wondering if you could create a wrapper. For example, if you wanted to change the return found in the UserService, then you could define a UserServiceWrapper implementation with the overrides for the methods where you wanted to change the response structure. But now that I am looking at the code, that wouldn&amp;#39;t work because the return type needs to be specific.  Something in the&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;com.liferay.portal.jsonwebservice&lt;br /&gt;might be overridable if it is registered as an OSGI service, but honestly I think the easiest thing to do would be as you are suggesting. Just make your own REST service and minimize the amount of &amp;#34;customization&amp;#34;. If nothing else, that will always make your upgrade paths less painful!&lt;strong&gt;&lt;/strong&gt;</summary>
    <dc:creator>Andrew Jardine</dc:creator>
    <dc:date>2020-04-11T15:49:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118905621" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118905621</id>
    <updated>2020-04-11T11:08:56Z</updated>
    <published>2020-04-11T11:08:56Z</published>
    <summary type="html">With the generated services under /api/jsonws, I believe, you can&amp;#39;t.&lt;br /&gt;With the &amp;#34;general&amp;#34; rest services, you can create using the module template &amp;#34;Rest&amp;#34;, you can do exactly as you wrote in your line.&lt;br /&gt;&lt;a href="https://help.liferay.com/hc/en-us/articles/360018166411-JAX-RS-"&gt;https://help.liferay.com/hc/en-us/articles/360018166411-JAX-RS-&lt;/a&gt;&lt;br /&gt;@GET&lt;br /&gt;  public Response appHomepage(@Context User user, @Context HttpServletRequest request) {&lt;br /&gt;      Something result;&lt;br /&gt;      ...&lt;br /&gt;      return Response.status(200).entity(result).build();&lt;br /&gt;    } catch (AccessDeniedException e) {&lt;br /&gt;      return Response.status(403).build();&lt;br /&gt;    } catch (Exception e) {&lt;br /&gt;      LOGGER.error(e);&lt;br /&gt;      return Response.status(500).build();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;I have come to vastly prefer the Whiteboard webservices to the /api/jsonws webservices. They were fine, if I had a fitting entity, but awkward otherwise.</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2020-04-11T11:08:56Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118904865" />
    <author>
      <name>Andrew Jardine</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118904865</id>
    <updated>2020-04-10T20:56:10Z</updated>
    <published>2020-04-10T20:56:10Z</published>
    <summary type="html">Are you trying to use one of the out of the box JSONWS services that Liferay provides? or are you working with one that you have generated?</summary>
    <dc:creator>Andrew Jardine</dc:creator>
    <dc:date>2020-04-10T20:56:10Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118886128" />
    <author>
      <name>ali yeganeh</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118886128</id>
    <updated>2020-04-08T15:50:30Z</updated>
    <published>2020-04-08T15:50:30Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;strong&gt;&lt;/strong&gt; Hi Christoph Rabel&lt;br&gt;Do you have a sample code that I can return JSON and HTTP status code together&amp;nbsp; (look like JAX-RS api ) ?&lt;br&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;javax.ws.rs.core.Response.status( Response.Status.OK ).entity( myEntity );&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;strong&gt;Thank you for your reply.&lt;/strong&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>ali yeganeh</dc:creator>
    <dc:date>2020-04-08T15:50:30Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to return JSON and HTTP status code together in remote service meth</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118883785" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118883785</id>
    <updated>2020-04-08T15:15:06Z</updated>
    <published>2020-04-08T15:15:06Z</published>
    <summary type="html">I might be wrong here and the behavior was changed, but AFAIK, those API calls *always* return a HTTP 200 OK status code. We dont&amp;#39;t use them anymore, but we always returned the real status code as part of the message and handled it in the success callback.&lt;br /&gt;We only use the rest api anymore, we found it to be far more flexible than implementing the ServiceImpl methods.</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2020-04-08T15:15:06Z</dc:date>
  </entry>
  <entry>
    <title>How to return JSON and HTTP status code together in remote service method</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118875992" />
    <author>
      <name>ali yeganeh</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118875992</id>
    <updated>2020-04-07T13:40:35Z</updated>
    <published>2020-04-07T13:40:35Z</published>
    <summary type="html">Hi&lt;br /&gt;&lt;br /&gt;I  implement my application’s remote service methods in *ServiceImpl . &lt;br /&gt;&lt;strong&gt;How to return JSON and HTTP status code together?&lt;/strong&gt;</summary>
    <dc:creator>ali yeganeh</dc:creator>
    <dc:date>2020-04-07T13:40:35Z</dc:date>
  </entry>
</feed>
