Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POJO to JSON in Play framework

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?

like image 768
KingFu Avatar asked Mar 16 '13 16:03

KingFu


1 Answers

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.

like image 83
ndeverge Avatar answered Oct 27 '22 00:10

ndeverge