Json数据进入Java REST服务导致500错误

Json数据进入Java REST服务导致500错误,java,ajax,rest,post,Java,Ajax,Rest,Post,我试图将JSON对象列表发送到post请求中。我这里一直有500个错误。我觉得我没有在方法定义中将变量设置为正确的数据类型,但我也不确定应该设置什么 AJAX请求: function post_request(json_data) { $j.ajax({ url : '../api/createDisplayGroup/postHtmlVar/' + containerID[1] + '/' + containerType[1], data: JSON.

我试图将JSON对象列表发送到post请求中。我这里一直有500个错误。我觉得我没有在方法定义中将变量设置为正确的数据类型,但我也不确定应该设置什么

AJAX请求:

function post_request(json_data) {

    $j.ajax({
        url : '../api/createDisplayGroup/postHtmlVar/' + containerID[1] + '/' + containerType[1],
        data: JSON.stringify(json_data),
        dataType: 'json',
        type : 'post',
        contentType : 'application/json'
    }).done(function(response) {
        run_update(response);
    }).error(function(jQXHR, textStatus, errorThrown) {
        alert('error getting request');
    });
};
Java REST服务(仅限POST):

@POST
@路径(“/postHtmlVar/{containerId}/{contentType}”)
@使用(MediaType.APPLICATION_JSON)
公共列表postHtml(@PathParam(“containerId”)字符串containerId,@PathParam(“contentType”)字符串contentType,列表显示组){
Long contId=Long.parseLong(containerId);
Long contType=Long.parseLong(contentType);
//返回convertToResponse(peopleFilterService.getDisplayGroups(contId,contType))*/
返回testDisplayGroup();
}

您需要将输入的json字符串作为
@FormDataParam
。我认为您的JavaREST框架无法将json封送到JSONObject列表中。您可能需要创建一个表示json数据的类,并像下面这样定义您的方法:

public List<TabDefinition> postHtml(@PathParam("containerId") String containerId, @PathParam("contentType") String contentType, @FormDataParam MyJSonDataClass myJsonDataClassObj) {
public List postHtml(@PathParam(“containerId”)String containerId、@PathParam(“contentType”)String contentType、@FormDataParam MyJSonDataClass myJsonDataClassObj){

也许我不完全理解@FormDataParam,但如果我理解正确,这将允许我从表单字段中获取数据。我需要做的是将我的整个json对象数组从前端获取到rest服务中。是否可以使用json.stringify(jsonArray)并将该字符串分配给“隐藏”表单变量?@Deslyxia FormDataParam用于从帖子正文中读取参数。此时我是否将使用多部分/表单数据,而不是application/json?
public List<TabDefinition> postHtml(@PathParam("containerId") String containerId, @PathParam("contentType") String contentType, @FormDataParam MyJSonDataClass myJsonDataClassObj) {