Rohini Kumar
Rohini Kumar

Reputation: 249

How to post java collection to webservice in play framework

I have a custom java class CustomInput and I want to post List<CustomInput> objects to my java web service.

In play framework api, there is option to post using

ws.url(url).post()

where we can post either String, jsonNode

but i didn't find option to post any object or xml

My webservice signature looks like below

@POST
@Path(AppConstants.GET_ASSETS)
@Consumes(MediaType.APPLICATION_XML)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String getAssets(
        final MyRequestType objReqType) throws MyCustomException {

Can anybody tell me how can i achieve this.

Upvotes: 2

Views: 297

Answers (2)

Aur&#233;lien Thieriot
Aur&#233;lien Thieriot

Reputation: 5923

I encourage you to accept Json as a possible format to consume. That way, Jersey will be able to accept Json as your body and map it with your object (MyRequestType).

If you don't want to do that though, I'm afraid there is no way to provide an XML body to the post() method.

You have still the choice to find a Java library to make the Marshalling for you but I don't have any on the top of my head

Upvotes: 1

Aur&#233;lien Thieriot
Aur&#233;lien Thieriot

Reputation: 5923

How is your Web service handling plural parameters?

A list like: "arg=value1&arg=value2"

Or is it SOAP? (Or something else?)

Upvotes: 0

Related Questions