Hi Farazath,
Instead of parsing the string manually, you can create a java bean class so
that JAX-RS will parse it for you.
For an example, let's say you have a json payload like this.
{
"fname": "Farazath",
"lname": "Ahamed"
}
So you can create a java bean like this.
class User {
private String fname;
private String lname;
// getters and setters for above attributes
}
Then your method signature has to be changed to,
*public Response issueRPT(@Context HttpServletRequest request, User user)*
Hope this would help you.
Regards,
On Mon, Jun 15, 2015 at 4:35 AM, Farazath Ahamed <[email protected]>
wrote:
> Hi,
>
> I am in the process of developing a REST API using JAX-RS.
> The incoming request to the endpoint contains a JSON payload which needs
> to be processed.
>
> Currently I am using the following approach to access the payload
>
> @Path("/rpt")
> public class UmaAuthorizationEndpoint {
>
> private static final Log log =
> LogFactory.getLog(UmaAuthorizationEndpoint.class);
>
> @POST
> @Path("/")
> @Consumes("application/json")
> @Produces("application/json")
> *public Response issueRPT(@Context HttpServletRequest
> request,@Multipart(value="application/json") String jsonPayload){*
>
> *// rest of the code*
> *}*
>
> I am using the @Multipart annotation to get the payload as a String and
> continue with parsing the JSON.
>
>
> Is this the usual approach? If not, Is there an alternative approach to do
> this?
>
>
> --
> *A.Farasath Ahamed*
> Undergraduate | Department of Computer Science and Engineering,University
> of Moratuwa
> Article Writer | MoraSpirit
> Mobile: +94 777 603 866
> Blog: http://thepseudocode.blogspot.com
> E-Mail: [email protected]
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
--
Milan Harindu Perera
Software Engineer
*WSO2, Inc*
(+94) 77 309 7088
lean . enterprise . middleware
<http://lk.linkedin.com/in/milanharinduperera>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev