Showing posts with label restful service. Show all posts
Showing posts with label restful service. Show all posts

Saturday, June 24, 2017

How to pass date type parameter in a restful service

In certain use case, we might need to pass date type parameter from service consumer to service provider.
But date as a object is not allowed to transfer via http.

The are only 2 additional steps to resolve this problem
1. at consumer side, convert the date object to long value
2. at provider side, convert the long value back to date object.

in Javascript / Play / SpringBoot consumer, convert the date object to long value

new Date().getTime();



in Play / SpringBoot provider, convert the long date value to date object.

new Date( dateValueInLong );




Done!!



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...