Friday, March 17, 2017

How to post json to Liferay OSGI restful service


To post a json to a Liferay OSGI restful service,
the service method itself must be able to accept String as the input parameter.
the service method is then parse the json string to a json object
follow by the required function process
and lastly return the response to the service consumer


@POST
@Path("/addPerson")
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON)
public Response addPerson(final String personJsonString) {

    ObjectMapper mapper = new ObjectMapper();
    JsonNode personJson = mapper.readTree(personJsonString);

    /**
     * Process person json 
     * 
     */
    
    return Response.status(Response.Status.OK).build();
}



Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...