Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:01:25+00:00 2026-06-06T18:01:25+00:00

I`m using Play! Framework 2.0 and I’m new in this framework. How can I

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:01:26+00:00Added an answer on June 6, 2026 at 6:01 pm

    The method you are using is from Play 1.x, it is slightly different in Play 2.0. From the documentation, here is an example of how to reply to a sayHello JSON request

    @BodyParser.Of(Json.class)
    public static Result sayHello() {
      ObjectNode result = Json.newObject();
      String name = json.findPath("name").getTextValue();
      if(name == null) {
        result.put("status", "KO");
        result.put("message", "Missing parameter [name]");
        return badRequest(result);
      } else {
        result.put("status", "OK");
        result.put("message", "Hello " + name);
        return ok(result);
      }
    }
    

    The important part of this from what you are asking is the return ok(result) which returns a JSON ObjectNode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Play Framework, you can do something like this: public static void mymethod() {
I'm trying to test a model method using Play Framework 2.0 and Specs2. Global.scala
I'm just getting started with the Play Framework 2.0 (using current trunk 2.1-SNAPSHOT, Scala)
I'm learning using Play Framework and doing a demo app for it. For this
I'm using the Play! framework and I have a model (an Entity) that has
I am using the Play Framework in it's current version and my model classes
How can I join two tables by using java play framework and jpa, I
Let's say I have a Student entity like this implemented using the Play Framework's
I'm using play framework now, i already know we can specify the attachments path
I'm new at using Play Framework 2.0 (I am using Scala) and have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.