Java 使用AJAX从Spring中的POST请求返回列表

Java 使用AJAX从Spring中的POST请求返回列表,java,ajax,spring,google-app-engine,jackson,Java,Ajax,Spring,Google App Engine,Jackson,我目前在一个页面上有一个POST请求,请求检索课程列表 $.ajax({ headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, 'type': 'POST', 'url': '/search/request', 'data': JSON.stringify(data), 'dataType': 'json' });

我目前在一个页面上有一个POST请求,请求检索课程列表

$.ajax({
    headers: { 
      'Accept': 'application/json',
      'Content-Type': 'application/json' 
    },
    'type': 'POST',
    'url': '/search/request',
    'data': JSON.stringify(data),
    'dataType': 'json'
});
控制器中的相应方法返回课程列表:

@Controller
@EnableWebMvc
public class SearchController {
    // Some other methods

    @RequestMapping(value = "/search/request",  method = RequestMethod.POST)
    public @ResponseBody
    List<Lesson> search_lessons(@CookieValue("token") String token, @RequestBody SearchQuery query) {
        try {
            // Grab the user.

            // TODO: Implement search logic.
            List<Lesson> searchedLessons = lessonService.get_main_lessons_by_user(user);
            System.out.println(searchedLessons.size());
            return searchedLessons;
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
}

`

因此,去掉任何带有Objectify键的字段都可以使对象序列化。

类路径上有jackson吗?课程的结构是什么?是否存在任何可能发生的延迟加载?你看到什么记录了吗?您是否尝试添加异常处理程序?Jackson位于类路径上,因为它成功地序列化了
SearchQuery
对象。编辑注释以添加课程结构。假设它在return语句之前提示print语句,那么searchedLessons在返回之前就已经加载了。未记录任何内容,并且该方法已包含异常处理。该catch块不会捕获在序列化返回期间发生的异常,我怀疑该异常正在发生。任务或原始任务是否已加载?我想它们可能已加载,因为删除这些字段会导致成功的序列化。我不认为Jackson能够序列化Objectify键。
package com.dolphinblue.models;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;

import java.util.*;
/**
 * Created by FreddyEstevez on 3/21/17.
 * Represent model for lessons
 */
@Entity
public class Lesson implements Comparable<Lesson>{

    @Id private Long lesson_id;
    private Long index;
    private String title;
    @Index private String user_id; //user who is working on the lesson
    @Index private String creator_id; //user who created the lesson
    private List<Key<Task>> tasks; //holds lists of tasks ids for this lesson
    private double percent_complete; // Hold the percent of task the user has completed
    @Index private boolean shared;
    @Index private  boolean site_owned;
    private Key<Lesson> original_lesson;
    private String description;
    private int rating;
    //Date when lesson was last edited or changed.
    private Date last_edited;
    //Date when this lesson was last access by user working on it
    private Date last_accessed;