POJO to JSON in Play framework

若如初见. 提交于 2019-12-22 07:18:23

问题


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)

And my code is:

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

   }

Any ideas?


回答1:


Make sure you import the right Json class using import play.libs.Json.

You probably used play.api.libs.Json which is targeted for the Scala API, not the Java API.



来源:https://stackoverflow.com/questions/15451726/pojo-to-json-in-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!