POJO for JSON in the Play Framework

Trying to get Play 2.0 to return JSON from POJO. But I get an 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?

+5
source share
1 answer

Make sure you import the correct class Jsonusing import play.libs.Json.

You probably used play.api.libs.Jsonone that is for the Scala API, not the Java API.

+19
source

All Articles