0

I need help with the method signature on the updateGroup method. Here is the json im passing - its an array of actions.

    [{"action":"add","key":"104"}]

this is the method its being passed to

@PUT
@Path("/group/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public IRestResponse updateGroup(@PathParam("id") String GroupName,
                                 Object GroupActions){
    //Do Something...
}

What type should GroupActions be above to recieve the json. ? HashMap, ArrayList, some combination?

2 Answers 2

3

You can use whatever collection type you want: List, Collection, ArrayList, HashSet etc; or, what is sometimes better, array of specified type. So, one of:

public IRestResponse updateGroup(..., List<GroupAction> groupActions);
public IRestResponse updateGroup(..., GroupAction[] groupActions);
public IRestResponse updateGroup(..., HashSet<GroupActions> groupActions);

I am not quite sure why other answers suggest you use String: this is unlikely to work, for one (since default converters do not go back from JSON/XML type to String), but more importantly it is unnecessary extra work for no gain.

But if you absolutely want to do manual parsing (if so, use Jackson, it's what most frameworks use), you'd take input as InputStream and feed that to the parser. It's the optimal "raw type" to use and does not have registered handler to cause problems.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried to use String type and than parse it?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.