Why can't I convert a Person object to Json?
My persona Model:
@Entity public class Person extends Model { @Id private Long id; private String value; }
Controller Method:
import com.fasterxml.jackson.databind.JsonNode; import models.Person; import play.Logger; import play.db.ebean.Model; import play.mvc.Controller; import play.mvc.Result; import views.html.index; import java.util.List; import static play.data.Form.form; import static play.libs.Json.toJson; ... public static Result getJsonPersons() { List<Person> persons = new Model.Finder(Long.class, Person.class).all(); JsonNode jsonNode = toJson(persons); Logger.debug("JSON > "+jsonNode.toString()); return ok(jsonNode); }
Act:
GET /persons controllers.Application.getJsonPersons()
The JSON result returned by the controller method:
[{},{},{},{},{}]
source share