Jax RS不将List转换为JSON而是抛出500状态消息

时间:2017-10-08 15:40:17

标签: java json rest jax-rs

我使用JAX RS通过REST协议转换数据。我已经有很多工作功能,但我似乎无法转换以下内容:

函数即时调用

public List<Tweet> search(String input) {
    ArrayList<Tweet> foundTweets = new ArrayList<Tweet>();
    for(int i = 1; i <= this.tweets.size(); i++){
        if(this.find(new Long(i)).getContent().contains(input)){
            foundTweets.add(this.tweets.get(i));
        }
    }
    return foundTweets;
}

会抛出500错误状态代码

@POST
@Path("/search")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public List<Tweet> searchTweets(){
    return tweetService.searchTweets("content"); // this contains 10 items in list
}

但这可以作为例如

@POST
@Path("/getAll")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public List<Tweet> searchTweets(){
    return tweetService.getAll(); // returns list of tweets
}

我现在很困惑。我的推文模型中没有搜索方法。这可能是其中一个原因?我第一次使用JAX RS。

1 个答案:

答案 0 :(得分:0)

这一行添加了推文,但这些推文都是空的。所以我改变了我的代码,现在一切正常。

foundTweets.add(this.tweets.get(i));