UriInfo
is mainly used to get information form the URI/URL. getPathParameters()
return a Map
of key value pairs where the key is a string extracted from URI templates in @Path
. For instance @Path("{id}")
would put the id
as a key, and its value as the key value.
That being said, you don't want any information from the URI. What you want is the request body content. With application/json
, generally we can use POJOs to model the incoming data (as described here). You will need to make sure you have a JSON provider to handle the JSON to POJO deserialization. For help with that, I would need to know what Jersey version you are using (you can comment below if you need help).
Just to see the data coming in (without POJO conversion), you can just have a String
parameter, and the deserialization will pass the JSON as a String to the method
@POST
@Path("/persistlogs")
@Consumes("application/json")
public Object myMethod(String jsonData) {
System.out.println(jsonData);
}
As for sending the data, I would avoid using the .serializArray()
for the form. You are going to be left with JSON like
[
{
"name": "...",
"value": "..."
},
{
"name": "...",
"value": "..."
}
]
It's not very pretty to work with, as you will need something like Pair
class, which really has no semantic value. Better to just create a POJO that maps a Javascript model object to a Java object. This is also described in the first link.
UPDATE
for Jersey (1.x) JSON support, add the following Maven dependency
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.17.1</version>
</dependency>
Then in your web.xml, configure the JSON support.
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>