简体   繁体   English

在Play框架中将POJO转换为JSON

[英]POJO to JSON in Play framework

Trying to get Play 2.0 to return JSON from a POJO. 尝试获取Play 2.0以从POJO返回JSON。 But I recieve the error 但我收到错误

The method toJson(Writes<A>) in the type Json is not applicable for the arguments (Product)

And my code is: 我的代码是:

public static Result index(String date) {
     Product item = new Product();
    return ok(Json.toJson(item));

   }

Any ideas? 有任何想法吗?

Make sure you import the right Json class using import play.libs.Json . 确保使用import play.libs.Json导入正确的Json类。

You probably used play.api.libs.Json which is targeted for the Scala API, not the Java API. 您可能使用了针对Scala API(而非Java API)的play.api.libs.Json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM