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 9216367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:24:10+00:00 2026-06-18T02:24:10+00:00

When I used json in my controller class of Play! framework, I experienced something

  • 0

When I used json in my controller class of Play! framework, I experienced something that I didn’t know why.

I had two ajax calls so my controller class had two corresponding method like below:

@BodyParser.Of(BodyParser.Json.class)
public static Result categoryAdder() {
    ....(using json)....
}

Then,

@BodyParser.Of(BodyParser.Json.class)
public static Result pathCalculator() {
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart filePart = body.getFile("imageFile");
    ObjectNode jsonResult = Json.newObject();
    ....
}

I used ajaxForm that is a plug-in for jquery to pass a file as multipartFormData.
When I put @BodyParser.Of(BodyParser.Json.class) before method pathCalculator(), this method threw an null pointer exception on FilePart filePart = body.getFile("imageFile");. This meant the request didn’t have any file inside. However, when I removed @BodyParser.Of(BodyParser.Json.class) from the method pathCalculator(), it worked well. Does @BodyParser.Of(BodyParser.Json.class) be needed? I don’t know why. The weird thing is that the method categoryAdder() works well during @BodyParser.Of(BodyParser.Json.class) is placed before.

Is there someone who knows why this situation happens?

  • 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-18T02:24:11+00:00Added an answer on June 18, 2026 at 2:24 am

    When you use @BodyParser.Of(BodyParser.Json.class) you’re telling play to validate the Content-Type as application/json in your HTTP request body.

    If you’re passing JSON in the body of the request and use such body parser it will validate the content and throw an appropriate HTTP error if invalid. In the first case categoryAdder since you’re using/parsing JSON inside the method it makes sense and it’s perfectly right (adds the validation).

    In the second case (pathCalculator) the Content-Type is multipart/form-data and a JSON body parser isn’t needed as there is no JSON in the request body.

    Simply removing the body parser works and that’s what you should do.

    Content-Type is set in the jQuery ajax request.

    Ref: http://www.playframework.org/documentation/2.0.4/JavaBodyParsers

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

Sidebar

Related Questions

I have jQuery code that post data with JSON.stringify to controller class but when
I have created one application in j2me, I have used json parsing in that
Does anyone know when XML should be used instead of JSON and why? Thanks
I am new to JSON programming in J2ME. I discovered that Json is used
I used this below code on my asp.net controller to return Json object on
I'm trying to use AJAX and JSON inside CodeIgniter. I've never used either technologies
I have a controller that inherits from the org.springframework.web.servlet.mvc.AbstractController class I have configurated it
I have a controller that takes some json in the ?request body? and does
I've never used JSON before so I'm not familiar with its syntax. At the
I have used JSON::Any in my program to transfer the hash between client and

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.