I`m using Play! Framework 2.0 and I'm new in this framework. How can I return just a json representation of my model in white html page?
What I'm doing is
public static void messagesJSON(){
List<Message> messages = Message.all();
renderJSON(messages);
}
But I get Error : Cannot use a method returning Unit as an Handler
The Play JSON API provides implicit Writes for most basic types, such as Int , Double , String , and Boolean . It also supports Writes for collections of any type T that a Writes[T] exists. import play. json.
json() The json() method of the Request interface reads the request body and returns it as a promise that resolves with the result of parsing the body text as JSON .
Stringify a JavaScript Object Use the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.
How about
return ok(Json.toJson(Moments.all());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With