尝试让 Play 2.0 从 POJO 返回 JSON。但是我收到错误
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
类。
您可能使用了针对 Scala API 而不是 Java API 的 play.api.libs.Json
。
关于java - Play 框架中的 POJO 到 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15451726/