Play框架中的POJO到JSON [英] POJO to JSON in Play framework
本文介绍了Play框架中的POJO到JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试让Play 2.0从POJO返回JSON。但我收到错误
Trying to get Play 2.0 to return JSON from a POJO. But I recieve the error
The method toJson(Writes<A>) in the type Json is not applicable for the arguments (Product)
我的代码是:
public static Result index(String date) {
Product item = new Product();
return ok(Json.toJson(item));
}
任何想法?
推荐答案
确保使用 import play.libs.Json导入正确的
。 Json
类
Make sure you import the right Json
class using import play.libs.Json
.
您可能使用了 play.api.libs.Json
Scala API,而不是Java API。
You probably used play.api.libs.Json
which is targeted for the Scala API, not the Java API.
这篇关于Play框架中的POJO到JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文