【问题标题】:spring mvc ajax data truncated with Jacksonspring mvc ajax 数据被 Jackson 截断
【发布时间】:2015-11-24 12:51:45
【问题描述】:

0: {id: 1, name: "installation", description: "installing",…}

1:2

2:3

上面显示的是 ajax 的 o/p。有任何人面对或知道为什么缺少 1 和 2 对象中的数据。我试图在服务器端打印响应列表。那里没问题,所有的值都被打印出来了。但是当涉及到客户端时,数据丢失了

@RequestMapping(value="/events/month", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Event> getEventsForMonth()
{
    List<Event> events= eventService.getEventsForMonth();
    for(Event event:events)
        System.out.println(event.getName());

    return events;
}

【问题讨论】:

  • 您的模型类上是否有任何 Jackson 特定的注释,例如 @JsonIdentityInfo?

标签: java json ajax spring spring-mvc


【解决方案1】:

您的代码应生成偶数对象的 JSON 数组:[{"id":...}, {"id":...}]

首先尝试嗅探负载(例如通过 Zed Attach Proxy 或 Fiddler)以确认 Spring + Jackson 不包含多个 Event 对象。

如果是这种情况,请尝试验证您的 Spring 应用程序中是否存在 MappingJackson2MessageConverter 的任何奇怪配置。尝试删除它并观察默认 Jackson 配置的行为。

【讨论】:

    猜你喜欢
    • 2013-07-07
    • 2011-04-01
    • 2012-07-24
    • 2016-10-26
    • 2013-04-26
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    相关资源
    最近更新 更多